cancel
Showing results for 
Search instead for 
Did you mean: 

Stm32L4 internal temperature sensor measurement

maryam magdy
Associate II
Posted on July 02, 2018 at 22:38

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 mbed compiler:

include 'mbed.h'

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); }

}

5 REPLIES 5
Tilen MAJERLE
ST Employee
Posted on July 02, 2018 at 22:53

Hello,

you are already reading absolute temperature.

Best regards,

Tilen

henry.dick
Senior II
Posted on July 02, 2018 at 23:14

'

My question is how can I make the MCU measure the absolute temperature?'

I think you may find it helpful to read the datasheet relevant section. Your questions are answered there, by the most authoritative source ever.

Posted on July 02, 2018 at 23:32

So does this difference between real temperature and the one I measure makes sense? Because I read some people had only a difference of about 3 degC.

Jack Peacock_2
Senior III
Posted on July 03, 2018 at 04:14

As I recall the calibration for temperature is at 3V on the L4 series.  If you base your conversions on 3.3V for the ADC range you have to adjust the temperature samples.  One way to automate that is checking the 1.2V internal reference first, to get a better determination of what voltage is on your VDDA pin.  If you power directly from a battery it's mandatory to calibrate your ADC with VREFINT as the VDDA drops, otherwise your samples drift significantly as the battery runs down.

  Jack Peacock

Posted on July 03, 2018 at 08:42

Your sensor in inside package, thus if package heats, sensor will read higher temperature.