This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

tmp117测量温度高8.7℃

Other Parts Discussed in Thread: TMP117

TI专家,您好:

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

--------------------------------------------------------------------------------------------------------

代码:

uint16_t        temperature;
    uint8_t         txBuffer[3];
    uint8_t         rxBuffer[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    (第⑥步)