cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L452 temperature sensor

IP.2
Associate II

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?

6 REPLIES 6

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
Guru

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

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

There are several L4 examples that use the temperature sensor. Here is one:

https://github.com/STMicroelectronics/STM32CubeL4/blob/5e1553e07706491bd11f4edd304e093b6e4b83a4/Projects/NUCLEO-L476RG/Examples_LL/ADC/ADC_TemperatureSensor/Src/main.c

If you feel a post has answered your question, please click "Accept as Solution".
IP.2
Associate II

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.

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".