Sometimes, we need to measure or check the internal temperature of the microcontrollers for safety reasons. So, in this article, I’ll cover how to measure the Internal Temperature of STM32 microcontrollers using the STM32CubeIDE compiler. So let’s begin.

Disclaimer: Electricity is always dangerous. Proper skill is required to work with electricity. Do work at your own risk. The author will not be responsible for any misuse or harmful act or any mistake you make. The contents of this website are unique and copyright protected. Kindly don’t do any nonsensical act of copying and claiming it as yours. Most of the articles published here are kept open-source to help you. Take the knowledge for free and use it, but if you are interested you can buy the ready resources offered here. If you need any help or guidance feel free to comment below, the author will try to help you. Also, there can be affiliation links in the article. Which will not affect you anyway, but allows the author with some commission. So please don’t take it otherwise. Thanks.

Table of Contents

Advertisements

Why need to measure Internal Temperature?

The answer is simple, for safety. Sometimes the MCU can become overheated. So to ensure MCU is not getting burnt, and for safety measures, we can monitor this temperature from time to time. And is important for industrial systems where downtime should not be over a limit.

Internal Temperature of STM32

Steps:

First, after project creation or from any existing project, go to ADC settings and select the internal temperature sensing channel.

And from the Continuous Conversion: select Enable. And then from Rank, select the max sample you want. Note that, the more the sample more the time and the more stable the reading.

Now save the project to generate or add code to your existing project.

After saving, simply add the following lines. Note: You can set any name as you want for the variables.

Here, I took 5 samples and then made an average value. Which gives a stable reading. But keep in mind that, as this is an additional feature for a MCU or project, so you should allocate the memory for this task comparing other main tasks.

Now, the code is ready. Compile and debug for the result.

In my case, it was the result on average. Also, note that this reading will change frequently. And it depends on the internal CPU load. So you may find that the temperature is fluctuating within a limit.

Calculation:

Now, you may ask where I get the calculation. Then, you have to read this application note and goto page 236.

You will get a relation between the internal temperature sensor and the ADC. Now, what are those Vsense?

For that, you need to read the datasheet of your microcontroller. In my case, it was like this:

So, putting all these values, the equation forms like this:

V25 = 1.43
Avg_Slope = 4.3 mV/C = 0.0043 V/C
VSENSE = 3.3/4096 * ADCReading
Temperature (in °C) = {(1.43 – 3.3/4096 * ADCReading) / 0.0043} + 25
Temperature (in °C) = {332.558 – 0.187364 * ADCReading} + 25
Temperature (in °C) = 357.558 – 0.187364 * ADCReading

And this calculation is used in the code. Also note that you can do all these calculations within your code, but it will consume RAM and ROM. So, if you can simplify the calculations, MCU consumes less RAM. So? Why not?

End:

I hope, this article will help you in your project by adding protection or just for curiosity. See you soon with the next article.

You can read other articles too:

For Professional Designs or Help:

Loading

Also let me know what you want to get as the next article, comment below!


MKDas

Mithun K. Das; B. Sc. in EEE from KUET; Head of R&D @ M's Lab Engineering Solution. "This is my personal blog. I post articles on different subjects related to electronics in the easiest way so that everything becomes easy for all, especially for beginners. If you have any questions, feel free to ask through the contact us page." Thanks.

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

%d bloggers like this: