Skip to main content
Visitor II
December 28, 2023
Question

STM32L431KBU TEMEPRATURE SENSOR

  • December 28, 2023
  • 4 replies
  • 1423 views

Hello everyone, we want to read the value from the temperature sensor with ADC using the stm32f431kbu6 microprocessor. We use the code mentioned below.

 

#define TS_CAL_1 (*((uint16_t*)0x1FFF75A8)

#define TS_CAL_2 (*((uint16_t*)0x1FFF75CA)

 

float mcuTempCalculate (uint16_t tempADCval, uint16_t VrefIntADCval)

{

float temperature = 0;

temperature=(((130.0f-30.0f)/(TS_CAL_2-TS_CAL_1))*(3.3/3.0 * tempADCval - TS_CAL_1))+30.0f;

return temperature;

}

However, we read the temperature value as 6-8V. temADCval value is 863. Where might the problem be? Can you help?

    This topic has been closed for replies.

    4 replies

    Super User
    December 28, 2023

    > #define TS_CAL_2 (*((uint16_t)0x1FFF75CA)

    An asterisk (*) is missing after uint16_t here.

    JW

    LeyliferAuthor
    Visitor II
    December 28, 2023

    Actually, I forgot to add (*) in my code. While writing here, I am getting the values ​​I specified, even though there is (*).

    Super User
    December 28, 2023

    we read the temperature value as 6-8V.

    Cannot read higher than Vref. Check your ADC measurements. By the way VrefIntADCval is not used in your function and the compiler should print a warning.

     

    Super User
    December 28, 2023
    • Make sure you're using the same VREF+ voltage (3.0V per the datasheet) as what was used to get TS_CAL values. If your voltage is different, then adjust.
    • Use max sampling time or use a sampling time that meets the temperature sensor requirements per the datasheet.

    > we read the temperature value as 6-8V

    6-8V is a voltage range, not a temperature. Perhaps you meant 6-8F?

    > STM32L431KBU 

    > stm32f431kbu6 

    It's difficult to provide specific feedback when your post and code have typos. Copy/paste should be working.

    Super User
    December 28, 2023

    Unexpected temperature sensor readout is a recurring theme here, try to search.

    Often, calibration as outlined in reference manual, helps. Other possible sources of problems here.

    JW