Nucleo - F207ZG RTC Time Drift
Greetings Everybody,
I have Nucleo - F207ZG board. I have attached external 3.0 V coin battery to VBat and GND. I am configuring board for RTC peripheral. After configuring RTC time and again rechecking after 1 day the time starts to move ahead or time advances by few seconds. After 3 weeks RTC shows 15 seconds more than the actual time.
Below is the code of main while loop
while (1)
{
if(_set_rtc_time)
{
RTC_CalendarConfig();
_set_rtc_time = 0;
}
RTC_CalendarShow(aShowTime, aShowDate);
lcd_put_cur(3,0);
memcpy(_BUFFER_0._BUFFER,(char *)aShowTime, 8);
lcd_text_justify(&_BUFFER_0);
lcd_send_string(_BUFFER_0._BUFFER_OUT);
}
static void MX_RTC_Init(void)
{
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = 127;
hrtc.Init.SynchPrediv = 255;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
if((RCC->BDCR & RCC_BDCR_RTCEN) == 0)
{
if (HAL_RTC_Init(&hrtc) != HAL_OK)
{
Error_Handler();
}
}
}Below is RTC show function code
/**
* @brief Display the current time and date.
* showtime : pointer to buffer
* showdate : pointer to buffer
* @retval None
*/
static void RTC_CalendarShow(uint8_t *showtime, uint8_t *showdate)
{
RTC_DateTypeDef sdatestructureget;
RTC_TimeTypeDef stimestructureget;
/* Get the RTC current Time */
HAL_RTC_GetTime(&hrtc, &stimestructureget, RTC_FORMAT_BIN);
/* Get the RTC current Date */
HAL_RTC_GetDate(&hrtc, &sdatestructureget, RTC_FORMAT_BIN);
/* Display time Format : hh:mm:ss */
sprintf((char *)showtime, "%2d:%2d:%2d", stimestructureget.Hours, stimestructureget.Minutes, stimestructureget.Seconds);
/* Display date Format : mm-dd-yy */
sprintf((char *)showdate, "%2d-%2d-%2d", sdatestructureget.Month, sdatestructureget.Date, 2000 + sdatestructureget.Year);
}
