8 years ago.

Internal temperature from STM32L476

Today I tried using the example for reading the internal temperature sensor in the STM32L476 Discovery demo board by importing this project:

https://developer.mbed.org/teams/ST/code/STM32_ADC_InternalChannels/

However, it appears to give crazy results, and ones that show some strange interaction between ADC channels. For example, in my case in a room that measures 23C the project as given reports the following:

VBat = 4364.5 mV
Internal Temperature = -189.4 degree C
VBat = 4364.5 mV
Internal Temperature = -190.4 degree C
VBat = 4361.3 mV
Internal Temperature = -190.4 degree C
VBat = 4364.5 mV
Internal Temperature = -191.6 degree C

However if I comment out the line 27 where it reads battery voltage I get a very different temperature displayed:

STM32 Internal Channels example
Internal Temperature = 35.0 degree C
Internal Temperature = 45.6 degree C
Internal Temperature = 45.0 degree C
Internal Temperature = 45.3 degree C
Internal Temperature = 44.6 degree C

What is going on here?

I really would expect the temperature to be within a few degrees of reality, and not to be jumping about by what looks like several LSB from reading to reading.

Also what is odd is the example main.cpp is using a few hard-coded constants, and not the data sheet approach (for example section "16.3.31 Temperature sensor" in RM0351, Reference manual, STM32L4x6 advanced ARM-based 32-bit MCUs, DocID024597 Rev 4) to calibration where the expected values for 110C and 30C are given in read-only locations. I'm guessing accessible using code such as:

const uint16_t TS_CAL1 = *(uint16_t *)(0x1FFF75A8);
const uint16_t TS_CAL2 = *(uint16_t *)(0x1FFF75CA);

Just to add that I have some other peripherals attached to the demo board, but I thought the temperature sensor was internal so not impacted by that sort of thing.

posted by Paul Crawford 23 Nov 2016

1 Answer

8 years ago.

Concerning the Vbat problem there is a fix on-going on GitHub. In the meantime you can add this line just before the temp sensor is read in order to clear this bit: ADC->CCR &= ADC_CCR_VBATE;

But this example need to be improved in order to read a more realistic value on all ST boards, using calibration data, measure the real Vref etc.... We have remove it for the moment until this is fixed too.

Thanks.

Thanks for the quick reply identifying those issues. However the suggested line appears to use variables/constants that the on-line compiler does not recognise (I added some other stuff, so line 66 is just before it reads the temp sensor):

Error: Identifier "ADC" is undefined in "main.cpp", Line: 66, Col: 11
Error: Identifier "ADC_CCR_VBATE" is undefined in "main.cpp", Line: 66, Col: 23

Will you post here once the example is working OK?

posted by Paul Crawford 24 Nov 2016