cancel
Showing results for 
Search instead for 
Did you mean: 

right formula for calculating temperature sensor using STMF401RE Nucleo?

duybienle
Associate II
Posted on February 01, 2017 at 07:25

I'm using STM32F401RE Nucleo board to measure the ambient temperature. After the sampling process, I receive a digital value from ADC_CHANNEL_TEMPERATURE and I want to convert this digital value into degree celcius. I searched on the internet for this and I found two different methods:

Method 1: Page 226 in

http://www.st.com/content/ccc/resource/technical/document/reference_manual/5d/b1/ef/b2/a1/66/40/80/DM000968pdf/files/DM000968pdf/jcr:content/translations/en.DM000968pdf

Temp(degree) = (V_sense - V_25)/Avg_slope + 25

Method 2: Page 251 in

http://www.st.com/content/ccc/resource/technical/document/reference_manual/c2/f8/8a/f2/18/e6/43/96/DM000319pdf/files/DM000319pdf/jcr:content/translations/en.DM000319pdf

Temp(degree) = ( ( (110 - 80)*(TS_DATA - TS_CAL1) ) / (TS_CAL_2 - TS_CAL_1) ) + 30 Where: - TS_CAL2: temperature sensor calirbation value at 110 degree - TS_CAL1: temperature sensor calirbation value at 30 degree - TS_DATA: temperature sensor output from ADC

It confuses me which one is the correct formula for calculating the temperature in degree celsius. Although Method 1 is from reference manual of STM32F401, the temperature result doesn't look correctly. While Method 2 from reference manual of STM32F0 series, it looks more reasonable.

Still I don't know which formula should I apply when using STM32F401RE Nucleo board ?

Thanks

#stm32f401-nucleo #temperature-sensor
8 REPLIES 8
T J
Lead
Posted on February 01, 2017 at 08:07

I use the code for the '091

it works well, sitting at 42.2C

and you have a typo, it should be -30, not -80...

Posted on February 01, 2017 at 08:27

Thanks. Yes, the result is more resonable when using the code in RM0091 than in RM0368, and you're right I made a typo there. However it still confuses me. As far as I know STM32F401RE Nucleo is a STM32F401 series, and the RM0368 should be the right documentation for it, not the RM0091 (for STM32F0 series).

Posted on February 01, 2017 at 08:41

what temp are you getting,

42.2C is about 12C above ambient.

Posted on February 01, 2017 at 09:11

I got almost the correct ambient temperature (25 degree at room temperature). However in the reference manual, it says that there may be an offset in the measured/calculated temperature. This offset varies from device to device and it may reach 40 degree. So if you want to measure the absolute temperature, you have to perform an extra calibration.

Posted on February 01, 2017 at 10:01

what is your ambient temp ?

12C ?

Posted on February 02, 2017 at 08:33

I got 22oC ambient temperature at room temperature

lorenzo meneghello
Associate II
Posted on February 22, 2017 at 11:22

Hi all,

I'm also trying to set the internal sensor but I can't understand how to convert the ADC value in Celsius.. I'm 

using the code in RM0091 but it return bad result i.e. ambient temperature 18°C the uC read 0x876 with TS_CAL1= 0x704 TS_CAL2 = 0x53B so the result is about 46°C but if try to cool down the uC the temperature is always ~46°C.. 

Any idea?

Thanks.

Posted on February 22, 2017 at 12:10

I use this on my '091

I get 35c at the start and slowly ramps 42c after some time... at 28c ambient...

maybe you can show me , if I have made a mistake...

I expected to see a higher temp, but maybe it is not correct.

void readProcessorTemperature (void){ // ADC_Channel_AVE[AVE_ADC_ChannelCounter], HAL_ADC_Channel_Buffer[((ADC_RowCounter -1) & 0x0F)][Show_ADC_ChannelCounter]);// showing the last value from DMA of all channels 
//Temperature computation code example// Temperature sensor calibration value address #define TEMP110_CAL_ADDR ((uint16_t*) ((uint32_t) 0x1FFFF7C2))#define TEMP30_CAL_ADDR ((uint16_t*) ((uint32_t) 0x1FFFF7B8))#define VREFINT_CAL ((uint16_t*) ((uint32_t) 0x1FFFF7BA))#define VDD_CALIB ((uint16_t) (330)) // 3.3V rail#define VDD_APPLI ((uint16_t) (328)) // actually reads 3.28V on multimeter 
 int32_t AveTemperatureADC = ADC_Channel_AVE[VTemp_Ad16]; // from DMA continuous read
 double processorTemp; processorTemp = (double) AveTemperatureADC * VDD_APPLI / VDD_CALIB /16; processorTemp -= (double) *TEMP30_CAL_ADDR ; processorTemp *= (double) (110 - 30); processorTemp /= (double)(*TEMP110_CAL_ADDR- *TEMP30_CAL_ADDR); processorTemp += 30; processorTemperature = (int32_t) ((double)processorTemp *100);
}
�?�?�?�?�?�?�?�?�?