cancel
Showing results for 
Search instead for 
Did you mean: 

The reading of the internal temperature sensor with internal calibration parameters does not read a correct value.

LPizz.1
Associate II

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

8 REPLIES 8
Uwe Bonnes
Principal II

Double check your code:

  • Are the relevant parts enables
  • Does it read the right channel
  • Are you correcting with the right stored values and the right VDDA

LPizz.1
Associate II

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

LPizz.1
Associate II

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

> 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

LPizz.1
Associate II

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.

LPizz.1
Associate II

have someone else tried such measurement?

With which results?

Piranha
Chief II

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.

LPizz.1
Associate II

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