
TMP102 temperature sensor test using LPC824.
Dependencies: test_TMP102 mbed
main.cpp
- Committer:
- yasubumi
- Date:
- 2017-11-19
- Revision:
- 1:3241f6a5a51e
- Parent:
- 0:26352a9cd499
- Child:
- 2:40c813b1d6a3
File content as of revision 1:3241f6a5a51e:
#include "mbed.h" // TMP102 I2C slave address(ADD0 connected to GND) #define ADDR_TMP102 0x90 // TMP102 registers #define TMP102_Temp 0x00 #define TMP102_Conf 0x01 #define TMP102_Tlow 0x02 #define TMP102_Thigh 0x03 // Init I2C (SDA: dp4, SCL: dp5) I2C i2c(dp4, dp5); int main() { while(1) { i2c.write(ADDR_TMP102, 0x00, 1); //Pointer to the temperature register char reg[2]={0,0}; i2c.read(ADDR_TMP102, reg, 2); // read two bytes data // calculate temperature int16_t res = ((int8_t)reg[0] << 4) | ((uint8_t)reg[1] >> 4); float temp = (float) ((float)res * 0.0625); printf("Temp: %f\n\r", temp); wait(1.0); } }