47 enum TMP102_STATUSTYPES {
58 static enum TMP102_STATUSTYPES _TMP102_STATUS = 0x00;
70 if(!(_TMP102_STATUS & INITED)) {
71 PRINTFDEBUG(
"TMP102 init\n");
72 _TMP102_STATUS |= INITED;
74 TMP102_PWR_DIR |= TMP102_PWR_PIN;
75 TMP102_PWR_SEL &= ~TMP102_PWR_SEL;
76 TMP102_PWR_SEL2 &= ~TMP102_PWR_SEL;
77 TMP102_PWR_REN &= ~TMP102_PWR_SEL;
78 TMP102_PWR_OUT |= TMP102_PWR_PIN;
92 tmp102_write_reg(uint8_t reg, uint16_t val)
94 uint8_t tx_buf[] = { reg, 0x00, 0x00 };
96 tx_buf[1] = (uint8_t)(val >> 8);
97 tx_buf[2] = (uint8_t)(val & 0x00FF);
99 i2c_transmitinit(TMP102_ADDR);
101 PRINTFDEBUG(
"I2C Ready to TX\n");
103 i2c_transmit_n(3, tx_buf);
105 PRINTFDEBUG(
"WRITE_REG 0x%04X @ reg 0x%02X\n", val, reg);
115 tmp102_read_reg(uint8_t reg)
117 uint8_t buf[] = { 0x00, 0x00 };
120 PRINTFDEBUG(
"READ_REG 0x%02X\n", reg);
123 i2c_transmitinit(TMP102_ADDR);
125 i2c_transmit_n(1, &rtx);
129 i2c_receiveinit(TMP102_ADDR);
131 i2c_receive_n(2, &buf[0]);
134 retVal = (uint16_t)(buf[0] << 8 | (buf[1]));
144 tmp102_read_temp_raw(
void)
148 rd = tmp102_read_reg(TMP102_TEMP);
153 tmp102_read_temp_x100(
void)
157 int16_t abstemp, temp_int;
159 raw = (int16_t)tmp102_read_reg(TMP102_TEMP);
161 abstemp = (raw ^ 0xFFFF) + 1;
168 temp_int = (abstemp >> 8) * sign * 100;
169 temp_int += ((abstemp & 0xff) * 100) / 0x100;
186 tmp102_read_temp_simple(
void)
188 return (int8_t)tmp102_read_temp_x100() / 100;
Device drivers header file for tmp102 temperature sensor in Zolertia Z1 WSN Platform.
void i2c_enable(void)
Configure serial controller in I2C mode and set I2C speed.
I2C communication device driver header file for Zolertia Z1 sensor node.