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:温度检测问题

Guru**** 651100 points
Other Parts Discussed in Thread: TMP117
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/sensors-group/sensors/f/sensors-forum/1190065/tmp117-temperature-detection-issue

器件型号:TMP117

您好!

我们 尝试  使用柔性 PCB 通过 I2C 通信来运行温度传感器 TMP117。

我们多次尝试更改周围的温度并更改代码,但它给出了相同的响应,始终提供 68.2F。

您能不能建议我们应该怎么做。  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Khojem、

    感谢您在传感论坛上发帖。

    您可以分享原理图和布局图吗? 这将帮助我们解决任何潜在问题。

    此致、
    Nicole

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Nicole、

    当然、请查找随附的传感器原理图和柔性 PCB 照片、以供您参考

    此致、

    Khojem

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Khojem、

    我知道 Nicole 正在与您合作解决这个问题、但我将提供我的2分钱。 您的电路看起来很好。 让我们看看 Nicole 还能提供什么。  

    过去我也遇到过类似的问题。 我必须在初始化时将 TMP117变量设置为"0"、以清除损坏的数据。

    尝试从 TMP117读回原始数据、然后查看数据是恒定的、还是在您将手指放在 TMP117上时发生变化。  这将验证您是否实际正在读取 TMP117。 如果数据看起来是恒定的、那么您可能不会从 TMP117读取数据。

    最后、下面是我用于将数据转换为温度的代码的副本。 但愿这对您有所帮助。

    //  ======== TMP117_toIntCelsius ========
    //  Convert raw temperature register value to degrees Celsius rounded to the
    //  nearest integer
    //
     int32_t TMP117_toIntCelsius(int32_t x)
     {
         /* Optional: Add bias to round before the final truncation */
         x += (x >= 0) ? (1 << 6) : -(1 << 6);
    
         /* Convert value to whole number */
         x /= 1 << 7; /* use division so small negative values round to 0 */
    
         return x;
     }
    
     //
     //  ======== TMP117_toMilliCelsius ========
     //  Convert raw temperature register value to milli-degrees Celsius
     //
     int32_t TMP117_toMilliCelsius(int32_t x)
     {
         /* Scale to milli-degrees, convert value to a whole number */
         return ((1000 * x) >> 7);
     }
    
     //
     //  ======== TMP117_toFloatCelsius ========
     //  Convert raw temperature register value to degrees Celsius
     //
     float TMP117_toFloatCelsius(int32_t x)
     {
         /* Convert value to a float */
         return ((float)x * 0.0078125f);
     }
     
     
     
     
     // read 2 bytes of temperature data 0x0000 and store in data[0] and data[1]
     tmp = (((int32_t)(int8_t)data[0]) << 8) | data[1];
     
     // convert TMP117 data to temperature in C 
     tmp1170Temp = tmp;
     tmp1170TempAsIntCelsius = TMP117_toIntCelsius(tmp1170Temp);
     tmp1170TempAsMilliCelsius = TMP117_toMilliCelsius(tmp1170Temp);
     TMP117_I2C_2 = TMP117_toFloatCelsius(tmp1170Temp) + TMP117_OFFSET_2;
    
     

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    霍杰姆-  

    您的 MCU 和 TMP117之间是否需要电平转换器? -或者确保 J10引脚1是1.8VDC 而不是3.3?  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    Josh、您好!

    当前控制器和 TMP117在同一电压电平上=+3.3V。 我们对 PCB 进行了返工。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    大家好、Gordon、  

    感谢您的支持、但我们无法获得准确的数据、并且我们将不断获得相同的价值。

    此致、

    Khojem

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Khojem、

    您能否提供错误温度读取的示波器捕获以及从 TMP117读取的代码?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    //Library for TMP117-High-Precision-Digital-Temperature-Sensor
    //I have written it using HAL API.
    //I have not added exception handling in this library because it makes code bulky.
    //you can simply use exception handling in your main function.
    //Hope it helps!
    
    #include "TMP117.h"
    
    uint8_t TMP117_DeviceID = TMP117_GND;
    
    void TMP117_Init(I2C_HandleTypeDef *i2c) //this function will initialize the sensor using custom parameters
    {
          TMP117_set_Config(i2c,0x02,0x20);
          TMP117_set_Temp_Offset(i2c,0x00,0x00);
          TMP117_set_LowLimit(i2c,0x28,0x16);           //Set 22 Celcius
          TMP117_set_HighLimit(i2c,0x76,0x80);          //Set 60 Celcius
    }
    
    void TMP117_set_Averaging(I2C_HandleTypeDef *i2c,TMP117_AVE ave) //set the high and low limit register for alert
    {
    	 uint16_t reg_value = TMP117_get_Config (i2c);
    	 reg_value &= ~((1UL << 6) | (1UL << 5) );      	 	//clear bits
         reg_value = reg_value |( ( ave & 0x03 ) << 5);          //set bits
         uint8_t first = (reg_value&0x0F); 
    	 uint8_t second =reg_value>>8;
    	 TMP117_set_Config(i2c,first,second);
    }
    
    void TMP117_set_Alert_Temp(I2C_HandleTypeDef *i2c,uint8_t Lowfirst,uint8_t LowSecond,uint8_t Highfirst,uint8_t HighSecond)
    {
    	  uint8_t bufLow[3],bufHigh[3];
          bufLow[0]=TMP117_TempLowLimit;
          bufLow[1]=Lowfirst;     
          bufLow[2]=LowSecond;    
          HAL_I2C_Master_Transmit(i2c,TMP117_DeviceID,bufLow,2,HAL_MAX_DELAY);
          HAL_Delay(1);
    	  
          bufHigh[0]=TMP117_TempHighLimit;
          bufHigh[1]=Highfirst;     
          bufHigh[2]=HighSecond;   
          HAL_I2C_Master_Transmit(i2c,TMP117_DeviceID,bufHigh,2,HAL_MAX_DELAY);
          HAL_Delay(1);
    }
    
    float TMP117_get_Temp(I2C_HandleTypeDef *i2c) //This function will return the temp in float.
    {
          uint8_t buf[4];
          buf[0]=TMP117_TempReg;
          HAL_I2C_Master_Transmit(i2c,TMP117_DeviceID,buf,0,HAL_MAX_DELAY);
          HAL_Delay(1);
          HAL_I2C_Master_Receive(i2c,TMP117_DeviceID,buf,4,HAL_MAX_DELAY);
          float Temp= ((buf[0]<<8)|buf[1]) * 0.0078125;
          return Temp;
    }
    
    uint16_t TMP117_get_Config(I2C_HandleTypeDef *i2c) //this function will return the configuration register value
    {
          uint8_t buf[3];
          buf[0]=TMP117_ConfigReg;
          HAL_I2C_Master_Transmit(i2c,TMP117_DeviceID,buf,0,HAL_MAX_DELAY);
          HAL_Delay(1);
          HAL_I2C_Master_Receive(i2c,TMP117_DeviceID,buf,2,HAL_MAX_DELAY);
    	  uint16_t Config= ((buf[0]<<8)|buf[1]);
          return Config;
    }
    
    void TMP117_set_Config(I2C_HandleTypeDef *i2c,uint8_t first,uint8_t second) //this function will set the configuration register
    {
          uint8_t buf[3];
          buf[0]=TMP117_ConfigReg;
          buf[1]=first;     
          buf[2]=second;    
          HAL_I2C_Master_Transmit(i2c,TMP117_DeviceID,buf,2,HAL_MAX_DELAY);
          HAL_Delay(1);
    }
    
    void TMP117_set_HighLimit(I2C_HandleTypeDef *i2c,uint8_t first,uint8_t second) //this function will set the the high limit for alert
    {
          uint8_t buf[3];
          buf[0]=TMP117_TempHighLimit;
          buf[1]=first;     
          buf[2]=second;    
          HAL_I2C_Master_Transmit(i2c,TMP117_DeviceID,buf,2,HAL_MAX_DELAY);
          HAL_Delay(1);
    }
    
    uint16_t TMP117_get_HighLimit(I2C_HandleTypeDef *i2c) //this function will return the highlimit register value
    {
          uint8_t buf[3];
          buf[0]=TMP117_TempHighLimit;
          HAL_I2C_Master_Transmit(i2c,TMP117_DeviceID,buf,0,HAL_MAX_DELAY);
          HAL_Delay(1);
          HAL_I2C_Master_Receive(i2c,TMP117_DeviceID,buf,2,HAL_MAX_DELAY);
    			uint16_t HighLimit= ((buf[0]<<8)|buf[1]);
          return HighLimit;    
    }
    
    void TMP117_set_LowLimit(I2C_HandleTypeDef *i2c,uint8_t first,uint8_t second)//this function will set the low limit for alert
    {
          uint8_t buf[3];
          buf[0]=TMP117_TempLowLimit;
          buf[1]=first;     
          buf[2]=second;    
          HAL_I2C_Master_Transmit(i2c,TMP117_DeviceID,buf,2,HAL_MAX_DELAY);
          HAL_Delay(1);    
    }
    
    uint16_t TMP117_get_LowLimit(I2C_HandleTypeDef *i2c) //this function will return the lowlimit register value
    {
          uint8_t buf[3];
          buf[0]=TMP117_TempLowLimit;
          HAL_I2C_Master_Transmit(i2c,TMP117_DeviceID,buf,0,HAL_MAX_DELAY);
          HAL_Delay(1);
          HAL_I2C_Master_Receive(i2c,TMP117_DeviceID,buf,2,HAL_MAX_DELAY);
          return ((buf[0]<<8)|buf[1]);    
    }
    
    uint16_t TMP117_get_EEPROM_Unlock(I2C_HandleTypeDef *i2c) //this will return the EEPROM unlock register value
    {
          uint8_t buf[3];
          buf[0]=TMP117_EEPROM_Unlock;
          HAL_I2C_Master_Transmit(i2c,TMP117_DeviceID,buf,0,HAL_MAX_DELAY);
          HAL_Delay(1);
          HAL_I2C_Master_Receive(i2c,TMP117_DeviceID,buf,2,HAL_MAX_DELAY);
    			uint16_t Unlock= ((buf[0]<<8)|buf[1]);
          return Unlock;     
    }
    
    void TMP117_set_EEPROM_Unlock(I2C_HandleTypeDef *i2c,uint8_t first,uint8_t second) //by this function we will set the EEPROM register value for read and write
    {
          uint8_t buf[3];
          buf[0]=TMP117_EEPROM_Unlock;
          buf[1]=first;     
          buf[2]=second;    
          HAL_I2C_Master_Transmit(i2c,TMP117_DeviceID,buf,2,HAL_MAX_DELAY);
          HAL_Delay(1);
    }
    
    void TMP117_set_EEPROM1(I2C_HandleTypeDef *i2c,uint8_t first,uint8_t second) //this function will set EEPROM1 value
    {
          uint8_t buf[3];
          buf[0]=TMP117_EEPROM1;
          buf[1]=first;     
          buf[2]=second;    
          HAL_I2C_Master_Transmit(i2c,TMP117_DeviceID,buf,2,HAL_MAX_DELAY);
          HAL_Delay(1); 
    }
    
    uint16_t TMP117_get_EEPROM1(I2C_HandleTypeDef *i2c) //by this function we wiil get EEPROM1 value
    {
          uint8_t buf[3];
          buf[0]=TMP117_EEPROM1;
          HAL_I2C_Master_Transmit(i2c,TMP117_DeviceID,buf,0,HAL_MAX_DELAY);
          HAL_Delay(1);
          HAL_I2C_Master_Receive(i2c,TMP117_DeviceID,buf,2,HAL_MAX_DELAY);
    			uint16_t EEPROM1= ((buf[0]<<8)|buf[1]);
          return EEPROM1;     
    }
    
    void TMP117_set_EEPROM2(I2C_HandleTypeDef *i2c,uint8_t first,uint8_t second) //this function will set EEPROM2 value
    {
          uint8_t buf[3];
          buf[0]=TMP117_EEPROM2;
          buf[1]=first;     
          buf[2]=second;    
          HAL_I2C_Master_Transmit(i2c,TMP117_DeviceID,buf,2,HAL_MAX_DELAY);
          HAL_Delay(1);     
    }
    
    uint16_t TMP117_get_EEPROM2(I2C_HandleTypeDef *i2c) //by this function we wiil get EEPROM2 value
    {
          uint8_t buf[3];
          buf[0]=TMP117_EEPROM2;
          HAL_I2C_Master_Transmit(i2c,TMP117_DeviceID,buf,0,HAL_MAX_DELAY);
          HAL_Delay(1);
          HAL_I2C_Master_Receive(i2c,TMP117_DeviceID,buf,2,HAL_MAX_DELAY);
    			uint16_t EEPROM2= ((buf[0]<<8)|buf[1]);
          return EEPROM2;
    }
    
    void TMP117_set_EEPROM3(I2C_HandleTypeDef *i2c,uint8_t first,uint8_t second) //this function will set EEPROM3 value
    {
          uint8_t buf[3];
          buf[0]=TMP117_EEPROM3;
          buf[1]=first;     
          buf[2]=second;    
          HAL_I2C_Master_Transmit(i2c,TMP117_DeviceID,buf,2,HAL_MAX_DELAY);
          HAL_Delay(1);
    }
    
    uint16_t TMP117_get_EEPROM3(I2C_HandleTypeDef *i2c) //by this function we wiil get EEPROM3 value
    {
          uint8_t buf[3];
          buf[0]=TMP117_EEPROM3;
          HAL_I2C_Master_Transmit(i2c,TMP117_DeviceID,buf,0,HAL_MAX_DELAY);
          HAL_Delay(1);
          HAL_I2C_Master_Receive(i2c,TMP117_DeviceID,buf,2,HAL_MAX_DELAY);
    			uint16_t EEPROM3= ((buf[0]<<8)|buf[1]);
          return EEPROM3;     
    }
    
    void TMP117_set_Temp_Offset(I2C_HandleTypeDef *i2c,uint8_t first,uint8_t second) //this function will set the temperature offset value
    {
          uint8_t buf[3];
          buf[0]=TMP117_Temp_Offset;
          buf[1]=first;     
          buf[2]=second;    
          HAL_I2C_Master_Transmit(i2c,TMP117_DeviceID,buf,2,HAL_MAX_DELAY);
          HAL_Delay(1);
    }
    
    uint16_t TMP117_get_Temp_Offset(I2C_HandleTypeDef *i2c) //by this function we will get the temprature offset value
    {
          uint8_t buf[3];
          buf[0]=TMP117_Temp_Offset;
          HAL_I2C_Master_Transmit(i2c,TMP117_DeviceID,buf,0,HAL_MAX_DELAY);
          HAL_Delay(1);
          HAL_I2C_Master_Receive(i2c,TMP117_DeviceID,buf,2,HAL_MAX_DELAY);
    			uint16_t TempOffset= ((buf[0]<<8)|buf[1]);
          return TempOffset;
    }
    uint16_t TMP117_get_ID_Reg(I2C_HandleTypeDef *i2c) //This function will return the ID register
    {
          uint8_t buf[3];
          buf[0]=TMP117_ID_Reg;
          HAL_I2C_Master_Transmit(i2c,TMP117_DeviceID,buf,0,HAL_MAX_DELAY);
          HAL_Delay(1);
          HAL_I2C_Master_Receive(i2c,TMP117_DeviceID,buf,2,HAL_MAX_DELAY);
          uint16_t ID= ((buf[0]<<8)|buf[1]);
          return ID;
    }
    //Library for TMP117-High-Precision-Digital-Temperature-Sensor
    //I have written it using HAL Api.
    //I have not added exception handling in this library because it makes code bulky.
    //you can simply use exception handling in your main function.
    //Hope it helps!
    
    
    #ifndef      _TMP117_H_
    #define      _TMP117_H_
    
    #ifndef     __STM32F4xx_HAL_I2C_H
    #define     __STM32F4xx_HAL_I2C_H
    #endif	
    
    #include "main.h"
    
    #define     TMP117_GND 0x48<<1    //	GND
    #define     TMP117_VCC 0x49<<1    //	VCC
    #define     TMP117_SDA 0x4A<<1    //	SDA
    #define     TMP117_SCL 0x4B<<1    //	SCL
    
    /*------------Pointer Registers-----------------------*/
    
    #define     TMP117_TempReg    			 0x00
    #define     TMP117_ConfigReg  			 0x01
    #define     TMP117_TempHighLimit  	 0x02
    #define     TMP117_TempLowLimit    	 0x03
    #define     TMP117_EEPROM_Unlock     0x04
    #define     TMP117_EEPROM1           0x05
    #define     TMP117_EEPROM2        	 0x06
    #define     TMP117_Temp_Offset   	   0x07
    #define     TMP117_EEPROM3           0x08
    #define     TMP117_ID_Reg		         0x0F
    
    
    typedef enum _TMP117_AVE{NOAVE = 0, AVE8, AVE32, AVE64}TMP117_AVE;    //Averaging mode No Average, Average 8,32,64
    
    void TMP117_set_Averaging(I2C_HandleTypeDef *i2c,TMP117_AVE ave);    //set averaging
    
    void TMP117_set_Alert_Temp(I2C_HandleTypeDef *i2c,uint8_t Lowfirst,uint8_t LowSecond,uint8_t Highfirst,uint8_t HighSecond); //set the high and low limit register for alert
    
    float TMP117_get_Temp(I2C_HandleTypeDef *i2c); //Return the temperature in float.
    
    uint16_t TMP117_get_Config(I2C_HandleTypeDef *i2c); //Return TMP117 configuration register value
    
    void TMP117_set_Config(I2C_HandleTypeDef *i2c,uint8_t first,uint8_t second); // Set the configuration Reg for features.
    
    void TMP117_set_HighLimit(I2C_HandleTypeDef *i2c,uint8_t first,uint8_t second); //Set high limit for alert
    
    uint16_t TMP117_get_HighLimit(I2C_HandleTypeDef *i2c); //Get the high limit register value
    
    void TMP117_set_LowLimit(I2C_HandleTypeDef *i2c,uint8_t first,uint8_t second); //Set low limit for alert
    
    uint16_t TMP117_get_LowLimit(I2C_HandleTypeDef *i2c); //Get the low limit register value
    
    uint16_t TMP117_get_EEPROM_Unlock(I2C_HandleTypeDef *i2c); //Get EEPROM Unlock Register Value
    
    void TMP117_set_EEPROM_Unlock(I2C_HandleTypeDef *i2c,uint8_t first,uint8_t second); //Set EEPROM Unlock Register value
    
    void TMP117_set_EEPROM1(I2C_HandleTypeDef *i2c,uint8_t first,uint8_t second); //Set EEPROM1
    
    uint16_t TMP117_get_EEPROM1(I2C_HandleTypeDef *i2c); //Get the Value from EEPROM1
    
    void TMP117_set_EEPROM2(I2C_HandleTypeDef *i2c,uint8_t first,uint8_t second); //Set EEPROM2
    
    uint16_t TMP117_get_EEPROM2(I2C_HandleTypeDef *i2c); //Get the Value from EEPROM2
    
    void TMP117_set_EEPROM3(I2C_HandleTypeDef *i2c,uint8_t first,uint8_t second); //Set EEPROM3
    
    uint16_t TMP117_get_EEPROM3(I2C_HandleTypeDef *i2c); //Get the Value from EEPROM3
    
    void TMP117_set_Temp_Offset(I2C_HandleTypeDef *i2c,uint8_t first,uint8_t second); //Set temperature offset value
    
    uint16_t TMP117_get_Temp_Offset(I2C_HandleTypeDef *i2c); //Get temperature offset value
    
    uint16_t TMP117_get_ID_Reg(I2C_HandleTypeDef *i2c); //Get ID Register
    
    void TMP117_Init(I2C_HandleTypeDef *i2c); //Initialization by giving the parameters
    
    #endif
    

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Khojem、

    您能否布置一个示波器捕获的错误温度读数?

    此致、
    Nicole