The STM32 embeds a temperature sensor that is can be used to measure the temperature of the die.
It is connected internally to one of the channel of the ADC.
I am attaching a simple code that reads the temperature sensor and then converts in degree C.
Note that this cannot be used to measure ambient temperature.
You also need to be aware of the min and the max as I stated in the code:
/* Internal temperature sensor: constants data used for indicative values in */
/* this example. Refer to device datasheet for min/typ/max values. */
/* For more accurate values, device should be calibrated on offset and slope */
/* for application temperature range. */
#define INTERNAL_TEMPSENSOR_V25 ((int32_t)1430) /* Internal temperature sensor, parameter V25 (unit: mV). Refer to device datasheet for min/typ/max values. */
#define INTERNAL_TEMPSENSOR_AVGSLOPE ((int32_t)4300) /* Internal temperature sensor, parameter Avg_Slope (unit: uV/DegCelsius). Refer to device datasheet for min/typ/max values. */ /* This calibration parameter is intended to calculate the actual VDDA from Vrefint ADC measurement. */
I have tested this code on a STM32F103 MCU on the STM3210E-EVAL board.
To run the code please copy and unzip the project zipped at:
You can download the Cube Library from our website: st.com