2021-01-21 12:38 AM
On the STM32G071RB board, I tried to read the temperature using HAL-based conversion macros. At ambient temperature I get reading of 47 to 60 celsius depending on whether or not the HAL_ADCEx_Calibration_Start() is called to improve accuracy.
The macro I used are:
__LL_ADC_CALC_TEMPERATURE
__LL_ADC_CALC_VREFANALOG_VOLTAGE
Does anyone use those macros and get correct readings?
Can you guide me to solve the problem?
Where could I be wrong?
Thank you in advance.
Best regards
Luca
2021-01-21 03:12 AM
Double check your code:
2021-01-21 05:22 AM
At first thanks for your quick answer.
Yes, I enabled all what I need, read the righ channel and adjust the VDD reading.
The following code is to configure the temperature channel:
sConfig.Channel = ADC_CHANNEL_TEMPSENSOR;
sConfig.SamplingTime = ADC_SAMPLETIME_160CYCLES_5;
sConfig.Rank = 0;
HAL_ADC_ConfigChannel(&hadc1, &sConfig);
and inside the above call the sensor is enabled.
So I acquire the temperature and the VDD.
And then I convert the VDD reading to mV as below
mVvddref = __LL_ADC_CALC_VREFANALOG_VOLTAGE(bitVREF, LL_ADC_RESOLUTION_12B);
and finally
celsius = __LL_ADC_CALC_TEMPERATURE(mVvddref, bitTEMP,LL_ADC_RESOLUTION_12B);
but the result is nonsense (47 celsius) but repeatable.
Thk
Luca Pizzini
2021-01-21 05:30 AM
One last info, I tried on the NUCLEO board (micro STM32G071RBT6) and on a custom board (micro STM32G030K6) with the same results so the calibrations stored by ST I think are correct. I suppose the trouble must be in the firmware.
Bye
Luca Pizzini
2021-01-21 06:04 AM
> the result is nonsense (47 celsius)
Why do you think so? Did you measure consumption and calculate the expected internal temperature for given package?
Do you observe the required time after enabling the temperature sensor, and the required sampling time, according to datasheet?
Are other ADC conversion values (external voltage of known value, internal VREF) OK?
JW
2021-01-21 06:37 AM
I did expect something around 25 celsius because that is the ambient temperature. So 47 are too much.
I do not know how much is the internal temperature. Do you think it could be 47 degrees? I don't.
The sampling time I think is correct.
The VDD conversion is correct becuse I measured it and the result (into variable mVvddref in above code) match.
2021-01-21 06:39 AM
have someone else tried such measurement?
With which results?
2021-01-23 07:25 AM
At room temperature...
STM32F767ZIT6 (LQFP144) on NUCLEO-F767ZI: 34 C.
STM32F765VIT6 (LQFP100) on custom board: 39 C.
But that's with a CPU load of 0,16 % and all the rest of time spent in sleep mode. For a LQFP64 running some HAL based bloatware in a busy loop, 47 C seems to be reasonable internal temperature.
2021-01-25 02:32 AM
Ah, ok , thank you for the answer.
So I neglected that my CPU is running in loop 100% of the time. My fault.
Thanks a lot for pinpoint this.
Then I consider closed this question.
Bye
Luca Pizzini