HAL DTS How to Use ¶
- group DTS_How_To_Use
-
How to use the HAL DTS driver ¶
Caution: ¶
This is just a description of DTS functionality. In order to use the DTS peripheral, it must be calibrated, it means:
Calibration value of the ramp coefficient for the chosen temperature sensor (RAMP_COEFF) must not be 0, it is measured during tests in factory and stored in DTS_RAMPVALR register. This value is expressed in hertz per degree Celsius.
Calibration value of the T0 temperature for the chosen temperature sensor must be 30 or 130 degree Celsius (0 or 1), it is the temperature used during tests in factory and stored in DTS_T0VALR1 register.
The HAL DTS driver can be used as follows: ¶
Declare a hal_dts_handle_t handle structure and initialize the DTSx driver with a DTSx HW instance by calling the HAL_DTS_Init(). The DTSx clock is enabled inside the HAL_DTS_Init() if USE_HAL_DTS_CLK_ENABLE_MODEL > HAL_CLK_ENABLE_NO.
Configure the low level hardware (CLOCK, NVIC, HW trigger…):
Enable the DTSx clock if USE_HAL_DTS_CLK_ENABLE_MODEL is not defined or defined to HAL_CLK_ENABLE_NO.
NVIC configuration if you need to use interrupt process.
Configure the DTSx interrupt priority.
Enable the NVIC DTSx IRQ handle.
Proceed with the EXTI or LPTIM configuration if you need to use Hardware trigger.
LSE clock has to be activated when it is selected as reference clock .
Configure the reference clock by calling HAL_DTS_SetConfig(). this configuration is optional.
Configure trigger and sampling time by calling HAL_DTS_SetConfigSensor(). these configurations are optional.
Configure thresholds by calling HAL_DTS_SetSensorThresholds(), trigger by calling HAL_DTS_SetSensorTrigger() and sampling time by calling HAL_DTS_SetSensorSamplingTime(). All these unitary configurations are optional. Caution: When using the LSE clock or operating at low PCLK frequencies, it is important to increase the sampling value during threshold configuration. This helps reduce quantization errors and enhances the reliability of temperature readings.
Temperature measurement:
Polling mode usage
Start measuring temperature by calling HAL_DTS_StartSensor().
Caution: Due to DTS end of measure interrupt always enabled in this API, Disabling the NVIC DTSx IRQ before calling this function is mandatory.
Check if temperature measurement is ready or not by calling HAL_DTS_PollForSensorTemperature().
Retrieve the measured temperature by calling HAL_DTS_GetSensorTemperature().
Stop measuring temperature by calling HAL_DTS_StopSensor().
Interrupt mode usage
Start measuring temperature by calling HAL_DTS_StartSensor_IT().
Or by HAL_DTS_StartSensor_IT_Opt() to enable specific optional interrupts.
Wait for the end of temperaure measurement and/or high threshold or low threshold detection (HAL_DTS_CpltCallback() and/or HAL_DTS_HighThresholdCallback() or HAL_DTS_LowThresholdCallback() occurrence).
Retrieve the measured temperature by calling HAL_DTS_GetSensorTemperature().
Stop measuring temperature by calling HAL_DTS_StopSensor_IT().
Callbacks definition in interrupt mode: ¶
When the compilation define USE_HAL_DTS_REGISTER_CALLBACKS is set to 1, the user can configure dynamically the driver callbacks, via its own method:
Callback name
Default value
Callback registration function
CpltCallback
HighThresholdCallback
LowThresholdCallback
If one needs to unregister a callback, register the default callback via the registration function.
By default, after the HAL_DTS_Init() and when the state is HAL_DTS_STATE_CONFIGURED, all callbacks are set to the corresponding default weak functions.
Callbacks can be registered in handle global_state HAL_DTS_STATE_CONFIGURED.
When the compilation define USE_HAL_DTS_REGISTER_CALLBACKS is set to 0 or not defined, the callback registration feature is not available and weak callbacks are used, represented by the default value in the table above.