cancel
Showing results for 
Search instead for 
Did you mean: 

How to resolve the STM3F407VG RTC accuracy problems?

Vinay1
Associate II

Do we able to calibrate the RTC for better accuracy?

1 ACCEPTED SOLUTION

Accepted Solutions

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

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.

View solution in original post

5 REPLIES 5
Peter BENSCH
ST Employee

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.

thank you for your response

i tried RTC smooth digital calibration functions. unfortunately the time keep on get incremented by 2 minutes. i could not found where i missed.

could you pls share any example file of stm32f407 rtc calibration files.

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

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.

thank you