Skip to main content
Vinay1
Associate III
August 16, 2021
Solved

How to resolve the STM3F407VG RTC accuracy problems?

  • August 16, 2021
  • 5 replies
  • 2878 views

Do we able to calibrate the RTC for better accuracy?

This topic has been closed for replies.
Best answer by Peter BENSCH

Calibration can be done by just a call to HAL_RTCEx_SetSmoothCalib, which is part of stm32f4xx_hal_rtc_ex.c or by setting the required parameter manually. You have certainly read the above-mentioned section 26.3.11 carefully so that you will immediately understand how the following, very simple function works, which incidentally is independent of the target and does not yet contain a check for the range of parameters. Simply call it anywhere in your user program to set the correction value to -511 ... +512 steps:

/**
 * @brief Sets the new correction values for smooth calibration into RTC_CALR, fixed for calibration period of 32s
 * @param calibration value -511...+512 for calculating CALP, CALM[8..0]
 * @retval none
 */
void wr_LSEcalibration(int16_t LSEcalibrationvalue)
{
 if (LSEcalibrationvalue > 0)
 {
 if (HAL_RTCEx_SetSmoothCalib(&hrtc, RTC_SMOOTHCALIB_PERIOD_32SEC, RTC_SMOOTHCALIB_PLUSPULSES_SET, (uint32_t)(512-LSEcalibrationvalue)) != HAL_OK)
 {
 Error_Handler();
 }
 }
 else
 {
 if (HAL_RTCEx_SetSmoothCalib(&hrtc, RTC_SMOOTHCALIB_PERIOD_32SEC, RTC_SMOOTHCALIB_PLUSPULSES_RESET, (uint32_t)abs(LSEcalibrationvalue)) != HAL_OK)
 {
 Error_Handler();
 }
 }
}

Regards

/Peter

5 replies

Peter BENSCH
ST Technical Moderator
August 16, 2021

Yes, you can calibrate the RTC, e.g. with so called smooth calibration with a resolution of about 0.954ppm with a range from -487.1ppm to +488.5ppm.

You will find details about this process in the reference manual RM0090, section 26.3.11 (RTC smooth digital calibration) and in the examples in the repository, either online or your local copy.

Regards

/Peter

In order 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.
Vinay1
Vinay1Author
Associate III
August 17, 2021

thank you for your response