2021-10-20 02:40 AM
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?
2021-10-20 05:39 AM
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
2021-10-20 06:49 AM
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.
2021-10-20 10:16 AM
Damn there is a temp question each week! It deserves to become an ADC advertised example....
2021-10-20 10:19 AM
There are several L4 examples that use the temperature sensor. Here is one:
2021-10-20 06:05 PM
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.
2021-10-20 06:12 PM