7 months, 3 weeks ago.

Stm32L4 internal temperature sensor measurement

Hello, I'm trying to measure the ambient temperature using the nucleo l432kc internal temp sensor . I connect the MCU through the usb to my lapotp. With the code I'm currently using, the output temperature starts at 23 degC when I first connect the MCU and then it settles at 30. I'm guessing this is because the MCU heats up till it reaches 30. Room temperature should be about 24. When I test the sensor at the fridge, it goes down till around 10 which also makes sense (instead of about 5). My question is how can I make the MCU measure the absolute temperature? should I just add an offset? or should I play with the sample time or other parameters? This is the code I'm using:

  1. include "mbed.h"
  1. include "stm32l4xx_ll_adc.h"

AnalogIn adc_temp(ADC_TEMP);

int main() {

while(1) { int temp12 = adc_temp.read_u16() >> 4;

int temp = LL_ADC_CALC_TEMPERATURE(3300, temp12, LL_ADC_RESOLUTION_12B);

printf("TMP%04d: %d\n", temp);

wait(1); }


Comment on this question

1 Answer

7 months, 2 weeks ago.

Hi Maryam,

If you consult the STM User's Manual for this device family:

in section 16.4.31 you'll see that each device has unique calibration values that will need to be read from the device and then applied to a formula to compute the aboslute temperature.

The STM-specific function you are using does use those calibration values. It is defined here:

Can you please check that you are using Mbed OS v5.9.1 (released about 2 weeks ago)? We see that two issues related to the STM32 ADC were fixed and maybe that is impacting the measurement:

-Ralph, Team Mbed

To post an answer, please log in.