Skip to main content
IP.2
Associate II
October 20, 2021
Question

STM32L452 temperature sensor

  • October 20, 2021
  • 4 replies
  • 2515 views

I'm using the below to calculate the temperature in STM32L452 CPU:

int16_t temperatureC ;

// ADC VREF is external 3V3

temperature = __HAL_ADC_CALC_TEMPERATURE (3300, ADC_val, ADC_RESOLUTION_12B);

For ADC_val = 1360 - then temperatureC is 164 Celsius, which is surely not the right temperature.

Did anyone do better?

This topic has been closed for replies.

4 replies

waclawek.jan
Super User
October 20, 2021

What value do you get when you convert the internal voltage reference?

Is this a "known good" board such as Nucleo or Disco, or your own?

JW

TDK
October 20, 2021

The temperature sensor has a minimum sample time requirement. Make sure you are meeting it.

If that's not it, maybe read the values in TEMPSENSOR_CAL1_ADDR / TEMPSENSOR_CAL2_ADDR directly to verify they are consistent with your measurement.

"If you feel a post has answered your question, please click ""Accept as Solution""."
S.Ma
Principal
October 20, 2021

Damn there is a temp question each week! It deserves to become an ADC advertised example....

TDK
October 20, 2021
"If you feel a post has answered your question, please click ""Accept as Solution""."
IP.2
IP.2Author
Associate II
October 21, 2021

Thanks to all responders, every answer helped to locate the missing bit which was this:

LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(ADC1), ADC_CCR_TSEN | ADC_CCR_VREFEN | ADC_CCR_VBATEN );

I still get 41C at room temperature, which seems higher than expected.

For waclawek.jan : Vref is 1V210, within range.

TDK
October 21, 2021
It’s measuring the junction temperature, which is going to be significantly higher than ambient. 41 C seems reasonable for typical clock speeds.
"If you feel a post has answered your question, please click ""Accept as Solution""."