cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F405 internal temperature sensor problem.

DL.4
Associate

Hello everybody

I have a problem with reading of the data from the internal temperature sensor.

I'm using last Cube IDE and Cube MX for configuring the project.

I created the project according to this example: "Get temperature from STM32 internal temperature sensor (simple library)" from refcircuit.(sorry, cannot attach links yet)

But without using of the uart part.

Temperature step depends on the APB2 frequency.

If it 84MHz then sampling period is about 47us with ADC prescaler = 8.

And in this case i see next posible values of ADC output: 961, 963, 993.

These values changes randomly.

If i heat it up, the temperature increasing according to the heater, but with strange steps.

If it 21MHz then sampling period is about 188us with ADC prescaler = 8.

In this case the ADC output is more accurate, and step looks much more better.

It is the strange behaviour for this MCU cause min sampling time must be 10us as in datasheet.

Also I have tried to use code without DMA and interrupts, just launch conversion by software, result is the same.

Does it normal? How can i get an accurate temperature at 84MHz?

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
Foued_KH
ST Employee

Hello @DL.4​ ,

Set input frequency HCLK 84 MHz.

Enable Scan Conversion ModeContinuous Conversion Mode and DMA Continuous Mode. Set two (Tmp CH and Ref CH) channels, the first should be Vrefint and the second is Sensor (can be in the order of your convenience) set maximum sampling time and Timer 3 Trigger Out event (this timer will start conversion).

Select Internal Clock for TIM3 and set timer frequency, in my case it will be:

APB/((PSC+1)(ARR+1)) = 84000000/((840-1+1)(10000-1+1)) = 10 Hz

(APB1/APB2 frequency, depending on using timer (in my case both peripheral bus have the same frequency))

  • Thus, conversion will be turned 10 times per second.

For more details check this AN2834 to get the best ADC accuracy in STM32 microcontrollers .

Foued

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

2 REPLIES 2
Foued_KH
ST Employee

Hello @DL.4​ ,

Set input frequency HCLK 84 MHz.

Enable Scan Conversion ModeContinuous Conversion Mode and DMA Continuous Mode. Set two (Tmp CH and Ref CH) channels, the first should be Vrefint and the second is Sensor (can be in the order of your convenience) set maximum sampling time and Timer 3 Trigger Out event (this timer will start conversion).

Select Internal Clock for TIM3 and set timer frequency, in my case it will be:

APB/((PSC+1)(ARR+1)) = 84000000/((840-1+1)(10000-1+1)) = 10 Hz

(APB1/APB2 frequency, depending on using timer (in my case both peripheral bus have the same frequency))

  • Thus, conversion will be turned 10 times per second.

For more details check this AN2834 to get the best ADC accuracy in STM32 microcontrollers .

Foued

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

DL.4
Associate

Hello Foued,

Thanks for your answer!

This was described in the article: https://refcircuit.com/articles/21-get-temperature-from-stm32-internal-temperature-sensor-simple-library.html

I've done it before and by some reason it doesn't work properly in my case.