2025-12-04 11:04 AM
Hello community,
I am new to stm32, and I need to read the temperature from the internal sensor of a stm32g4vet6.
I am at the point where I have read many things and have discovered that not all stm32's internal temperature sensors must be used the same way.
Currently I have asked to connect vref and temperature sensor to ADC5, asked for calibration of ADC5, and configured high values for the sampling time, and I can read adc-measured values for vref and temperature.
I can compute a temperature with
temperature = (130 - 30) * (Adc.Raw[0] * 33 / 30 - *TEMPSENSOR_CAL1_ADDR) / (*TEMPSENSOR_CAL2_ADDR - *TEMPSENSOR_CAL1_ADDR) + 30;
and I get plausible but unstable values. (the nominal value of my Vref is 3.3 V)
However I wonder if I should use the value of Vref measured by the ADC, and *VREFINT_CAL_ADDR, to get more stable values, and how ?
2025-12-04 11:30 AM
Consider adding more details here. In what way are the values both plausible and unstable?
If this is a custom board, duplicate the issue on known good hardware such as a nucleo board.
2025-12-08 2:00 AM
Thank you for your answer.
I work with a custom board, and unfortunately I do not have a 'known good hardware such as a nucleo board'.
My board is running at room temperature and in cruise mode, doing nothing else currently than measuring temperature. With the above formula, the temperatures I get, measured every seconds, are between 27 and 37 C,
with sudden jumps from 27 to 37 or conversely. After some more time, temperatures are between 29 and 41 C, with again sudden jumps. Temperature are plausible, but the jumps are not.
Could measuring vref and using ^VREFINT help getting a more stable measure ? How ?
2025-12-08 2:24 AM
@phdm wrote:Could measuring vref and using ^VREFINT help getting a more stable measure ? How ?
Yes. The temperature sensor is calibrated at a specific supply voltage (read datasheet for the correct value, it's not always the same for all processors, it's not always in the header file). By measuring the supply voltage using VREFINT you can get better accuracy. I use it.