Because of the holidays, TI E2E™ design support forum responses will be delayed from Dec. 25 through Jan. 2. Thank you for your patience.

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: Temperature detection issue

Part Number: TMP117

HI,

We are trying to run Temperature sensor TMP117 through I2C communication using flex PCB.

We tried many times to change the temperature around and change the code but it gives same response , it gives 68.2F all the time.

Could you suggest what should we do. 

  • Hi Khojem,

    Thank you for posting to the Sensing forum.

    Could you please share an image of the schematic and layout? This will help us troubleshoot any potential issues.

    Best regards,
    Nicole

  • Hello Nicole,

    Sure, Please find attached sensor schematic and flex PCB photos for your reference

    Best Regards,

    Khojem

  • Hi Khojem,

    I know that Nicole is working with you on this, but I will offer my 2 cents. your circuits looks good. Let's see what Nicole has to offer as well. 

    In the past I have had a similar problem. I had to set my TMP117 variables equal to "0" when initialized to get rid of corrupt data.

    Try reading back the raw data from the TMP117 and see if the data is constant or changes as you put your finger on the TMP117. This will verify that you actually are reading the TMP117. If the data appears to be constant then you may not be reading data from the TMP117.

    Lastly, below is a copy of the code I use to convert the data to temperature. I hope it helps.

    //  ======== 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;
    
     

  • Khojem - 

    Do you not need a level shifter between your MCU and the TMP117? - or make sure J10 pin1 is 1.8VDC instead of 3.3? 

  • Hi Josh,

    Currently Controller as well as TMP117 on same voltage level = +3.3V. We reworked on PCB.

  • HI Gordon, 

    Thank you for the support but we are not able to get accurate data and we are receiving same value again and again.

    Regards,

    Khojem

  • Hi Khojem,

    Can you please provide an oscilloscope capture of the incorrect temperature reads, as well as the code for reading from the 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
    

  • Hi Khojem,

    Can you post an oscilloscope capture of the incorrect temperature reads?

    Best regards,
    Nicole