#include <stdio.h>
#include <unistd.h>
#define TMP102_ADDRESS 0x48
#define TMP102_ADDR_PIN0 0x01
#define TMP102_TEMPERATURE_REGISTER 0x00
#define TMP102_CONFIGURATION_REGISTER 0x01
#define TMP102_TLOW_REGISTER 0x02
#define TMP102_THIGH_REGISTER 0x03
#define TMP102_OS 0x80
#define TMP102_R1 0x40
#define TMP102_R0 0x20
#define TMP102_F1 0x10
#define TMP102_F0 0x08
#define TMP102_POL 0x04
#define TMP102_TM 0x02
#define TMP102_SD 0x01
#define TMP102_CR1 0x80
#define TMP102_CR0 0x40
#define TMP102_AL 0x20
#define TMP102_EM 0x10
#define TMP102_CR_0_25Hz CR0
#define TMP102_CR_1Hz CR1
#define TMP102_CR_4Hz CR1
#define TMP102_CR_8Hz (CR1 + CR0)
#define TMP102_CONVERSION 0.0625
int main(void)
{
uint8_t rxBuffer[2] = {0};
uint8_t txBuffer[1] = {TMP102_TEMPERATURE_REGISTER};
uint32_t temperature = 0;
float temperature_f = 0;
{
return 1;
}
{
return 1;
}
{
return 1;
}
{
return 1;
}
{
return 1;
}
temperature = rxBuffer[0] << 4;
temperature |= rxBuffer[1] >> 4;
temperature_f = temperature * TMP102_CONVERSION;
fprintf(stdout, "Temperature: %.2f Celsius\n", temperature_f);
return 0;
}