cancel
Showing results for 
Search instead for 
Did you mean: 

Wrong readout of STM32U575 Temperature Sensor

RLanz.2
Associate III

Hello,

Trying to read STMU575 Internal Temperature Sensor, we get wrong readout.
We need you advise on what is required to get correct temperature readouts from the STM32U575 temperature sensor.

A. We use ADC4 configured as follows:

RLanz2_0-1736414650287.png

B. The below detailed code, which runs periodically every ~1[sec], is responsible for the following:
1. Read the temperature sensor via the ADC.
2. Read the two calibration factors for 30 and 130 Celsius, and make two corrections due to:
    2.1 Reference voltage is 3.3V and not 3.0V.
    2.2 ADC4 is 12bits and not as ACD1 which is 14bits.
3. Convert the ADC readout using the corrected calibration factors and the formula, as in STM32U575 datasheet.

But on room temperature we get a readout of more than 50 Celsius!
Using a IR camera pointed to the STMU575 MCU we read less than 30 Celsius.
Note that the temperature readout did respond to heating by a blower (temperature increased by more than 20 degrees), but it took it more than 20[sec] to 'respond' and increase from more than 50 Celsius to more than 70 Celsius.

According to some related info I've found on Practical experience | Correctly measure temperature based on STM32U5 on-chip temperature sensor (see https://mcu.eetrend.com/content/2024/100578516.html),
the calibration factors values read from MCU EEPROM seem reasonable, and the conversion formula seems ok, and the problem is probably related to the temperature value readout from the sensor via the ADC.

The code is attached here:

 

#define hadc_mcu_temp_sens hadc4

 

uint16_t Read_Temperature(void)
{
uint16_t raw_adc_value;

HAL_ADC_Start(&hadc_mcu_temp_sens); // Start ADC conversion
if (HAL_ADC_PollForConversion(&hadc_mcu_temp_sens, ADC_MAX_DELAY_MS) == HAL_OK)
{
raw_adc_value = HAL_ADC_GetValue(&hadc_mcu_temp_sens); // Read ADC value
}
HAL_ADC_Stop(&hadc_mcu_temp_sens); // Stop ADC conversion
return raw_adc_value;
}

float Calculate_Temperature(uint16_t raw_adc_value)
{
uint16_t *TS_CAL1 = (uint16_t*) 0x0BFA0710; // Calibration @ 30°C
uint16_t *TS_CAL2 = (uint16_t*) 0x0BFA0742; // Calibration @ 130°C
float TS_CAL1_corrected = (((float)(*TS_CAL1))/4.0)*3.0/3.3;
float TS_CAL2_corrected = (((float)(*TS_CAL2))/4.0)*3.0/3.3;
float TS_CAL1_TEMP = 30.0; // Calibration temperature 1
float TS_CAL2_TEMP = 130.0; // Calibration temperature 2

float temp_calculated = ((TS_CAL2_TEMP - TS_CAL1_TEMP)/(TS_CAL2_corrected - TS_CAL1_corrected))*(raw_adc_value - TS_CAL1_corrected) + TS_CAL1_TEMP;
return temp_calculated;
}

float Get_Temperature(void)
{
uint16_t adc_value = Read_Temperature();
return Calculate_Temperature(adc_value);
}


Thank you!

0 REPLIES 0