How to configure and use the DTS (Digital Temperature Sensor) on the STM32H7
1. Introduction
The DTS (Digital Temperature Sensor) was introduced in our high performance STM32H7 family. In this article we will see how to configure and use this peripheral on a STM32H723.
2. Prerequisites
- Hardware
- Micro USB cable used to power the Nucleo board from a host machine and to load the code into the STM32
- Nucleo-H723
3. Theory
The DTS generates a square wave with a frequency that is proportional to the temperature. The frequency is measured either with the PCLK or the LSE clock. In this article we will learn how to configure and use this peripheral using the STM32CubeIDE and a Nucleo-H723.The frequency measurement will be started using software. The Reference clock will be the high-speed clock which is PCLK with no divider and will measure with calibration so the quick measurement will be disabled. For Sampling Time, we will use 15 samples. A High and Low Threshold can be set to define a temperature window, that if exceeded, will generate an interrupt (i.e., if the temperature is higher or lower than the thresholds).Here is the block diagram of the DTS: Let’s see how to enable, configure and use the peripheral using our STM32CubeIDE.
4. Steps
-
Open STM32CubeIDE
-
Create a new project using the NUCLEO-H723 board
-
Give a name to the project
-
Initialize all peripherals with their default settings
Click Yes when the Board Project Options window pops up.
-
Configure DTS
You will find the DTS in the Analog category in the Pinout and Configuration Tab.
-
Enable DTS
Enable the Peripheral
-
Configure DTS
We will configure the DTS as described earlier in the article:
- Start the measurement using software.
- The Reference clock will be the high-speed reference clock which is PCLK with no divider.
- We will measure with calibration so the quick measurement will be disabled.
- For Sampling Time, we will use 15 samples to get the highest precision.
- No thresholds will be used in this example
-
Generate Code
Save the project, that will also generate the code.
-
Add code to main.c
First we will declare a variable to store the temperature we will measure.
/* USER CODE BEGIN PV */
static int32_t Temperature;
/* USER CODE END PV */
Let’s add some code to start the peripheral, start as measurement, stop and the de-init the DTS.
/* USER CODE BEGIN 2 */
/* Start DTS peripheral */
if(HAL_DTS_Start(&hdts)!= HAL_OK)
{
/* DTS start Error */
Error_Handler();
}
/* Get temperature in deg C */
if(HAL_DTS_GetTemperature(&hdts, &Temperature)!= HAL_OK)
{
/* DTS GetTemperature Error */
Error_Handler();
}
/* Stop DTS peripheral */
if(HAL_DTS_Stop(&hdts)!= HAL_OK)
{
/* DTS stop Error */
Error_Handler();
}
/* De-initialize DTS peripheral */
if(HAL_DTS_DeInit(&hdts) != HAL_OK)
{
/* DTS De-initialization Error */
Error_Handler();
}
/* USER CODE END 2 */
-
Build the project, enter debug mode and run the code
After the project is built, enter a debug sessionNow add the variable "Temperature" to the Live Watch Window.Run the code:You should now see the measured Temperature being displayed in degrees Celsius.Please keep in mind that this is the die temperature and not the ambient temperature.
5. Links
Datasheet - STM32H723VE STM32H723VG STM32H723ZE STM32H723ZG - 32-bit Arm® Cortex®-M7 550 MHz MCU, up to 1 MB Flash memory, 564 KB RAM, 35 comms peripherals and analog interfacesSTM32H723/733, STM32H725/735 and STM32H730 Value line advanced Arm®-based 32-bit MCUs - Reference manualSTM32CubeIDE - Integrated Development Environment for STM32 - STMicroelectronicsNUCLEO-H723ZG - STM32 Nucleo-144 development board with STM32H723ZG MCU, supports Arduino, ST Zio and morpho connectivity - STMicroelectronics