cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G0B1: internal temperature sensor

xlrl
Associate II

I am trying to measure/calculate the internal temperature of an STM32G0B1VE design.

The algorithm used is taken from the reference manual RM0444 Rev 5 pages 376-378:

Temperature in degreesC = ((TS_CAL2_TEMP-TS_CAL1_TEMP) / (TS_CAL2-TS_CAL1)) * (TS_DATA-TS_CAL1) + TS_CAL1_TEMP

The calibration values are taken from the data sheet, see stm32g0b1ve.pdf (DS13560 Rev 1) page 25.

TS_CAL1_TEMP = 30 (defined in data sheet)

TS_CAL2_TEMP = 130 (defined i data sheet)

TS_CAL1 = 0x3FF (speficic to my controller, retrieved from 0x1FFF75A8)

TS_CAL2 = 0x560 (specific to my controller, retrieved from 0x1FFF75CA)

measured = 0x39F

If I run the calculation, I get 3°C. Is there something I did wrong?

Attached is a minimal STM32CubeMX/STM32CubeIDE example

11 REPLIES 11
xlrl
Associate II

Oh, and thanks a lot for your help!

Philippe Cherbonnel
ST Employee

Hello @xlrl​ ,

Temperature conversion from ADC raw conversion to physical value is a little bit tricky (2 methods using typical datasheet parameters or calibration data, values taking into account measurement conditions. For example, as mentioned by @TDK​ , Vref+ voltage corresponding to ADC conversion data).

A macro is available to compute easily the temperature in degree Celsius: macro __LL_ADC_CALC_TEMPERATURE in file "stm32g0xx_ll_adc.h".

Usage:

__LL_ADC_CALC_TEMPERATURE(VDDA_APPLI, <ADC conversion data of temperature sensor>, LL_ADC_RESOLUTION_12B);

You can refer to examples in STM32G0 FW package (and port them on your target STM32G01B):

Using ADC LL driver:

...\Firmware\Projects\NUCLEO-G071RB\Examples_LL\ADC\ADC_MultiChannelSingleConversion

Using ADC HAL driver:

...\Firmware\Projects\STM32G081B-EVAL\Examples\ADC\ADC_MultiChannelSingleConversion

Best regards

Philippe