TI中文支持网
TI专业的中文技术问题咨询交流网站

tmp117测量温度高8.7℃

TI专家,您好:

目前使用tmp117测温,使用实例代码配置后,读取室温为31.3℃,但实际室温为23.6℃,用手捏住温度会上升。测试了两个芯片问题均相同,烦请协助分析下原因,谢谢!

——————————————————————————————————–

代码:

uint16_ttemperature;uint8_ttxBuffer[3];uint8_trxBuffer[2];I2C_Transaction i2cTransaction;/* Point to the T ambient register and read its 2 bytes */txBuffer[0] = TMP117_OBJ_TEMP;i2cTransaction.slaveAddress = Board_TMP_ADDR;i2cTransaction.writeBuf = txBuffer;i2cTransaction.writeCount = 1;i2cTransaction.readBuf = rxBuffer;i2cTransaction.readCount = 2;if (I2C_transfer(i2c, &i2cTransaction)) {/* Extract degrees C from the received data; see TMP117 datasheet */temperature = (rxBuffer[0] << 8) | (rxBuffer[1]);/** If the MSB is set '1', then we have a 2's complement* negative value which needs to be sign extended 7.8125 mC*/if (temperature & 0x8000) {temperature ^= 0xFFFF;temperature  = temperature + 1;}}else {Display_printf(dispHandle, 0, 0, "I2C Bus fault");}/* Start the next conversion in one-shot mode */txBuffer[0] = TMP117_OBJ_CONFIG;txBuffer[1] = 0x0C;txBuffer[2] = 0x20;i2cTransaction.slaveAddress = Board_TMP_ADDR;i2cTransaction.writeBuf = txBuffer;i2cTransaction.writeCount = 3;i2cTransaction.readBuf = rxBuffer;i2cTransaction.readCount = 0;/* Wait for the I2C access for configuration. If it fails* then sleep for 1 second and try again. This is a must* to do before reading the device. */while(!(I2C_transfer(i2c, &i2cTransaction)));return(temperature);

———————————————————

tmp117使用方法:

①配置config寄存器为如上单次模式。

—-以下为while(1)—-

②读取config寄存器。

③读取温度数据。

④读取config寄存器数据。

⑤配置config寄存器为如上单次模式。

⑥读取config寄存器数据。

通过打印config寄存器配置:如下

0> <info> app: cfg0:2C20    (第②步)
0> <info> app: T:3136          (第③步)
0> <info> app: cfg1:0C20    (第④步)
0> <info> app: cfg2:0C20    (第⑥步)

user6359378:

回复 Viki Shi:

例程在哪里

YiKai Chen:

回复 user6359378:

如果是CC2640R2的話例程可以在 dev.ti.com/…/node 找到
如果是CC26x2r的話例程可以在dev.ti.com/…/node 找到

user6359378:

回复 YiKai Chen:

非常感谢

赞(0)
未经允许不得转载:TI中文支持网 » tmp117测量温度高8.7℃
分享到: 更多 (0)