How to resolve the STM3F407VG RTC accuracy problems?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-15 11:35 PM
Do we able to calibrate the RTC for better accuracy?
Solved! Go to Solution.
- Labels:
-
RTC
-
STM32F4 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-17 6:55 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-16 1:25 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-16 10:28 PM
thank you for your response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-17 5:01 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-17 6:55 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-23 3:21 AM
thank you
