cancel
Showing results for 
Search instead for 
Did you mean: 

Nucleo - F207ZG RTC Time Drift

Nimit Vachhani
Associate III

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);

}

 

Below is rtc init code
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);
}
 
1 ACCEPTED SOLUTION

Accepted Solutions

I don't use F2, but look for app notes like: AN2604 Application note STM32F101xx and STM32F103xx RTC calibration.

Besides, synchronisation with some external precise reference clock, GPS signal, ...  seems possible.

hth

KnarfB 

View solution in original post

5 REPLIES 5
KnarfB
Principal III

The board schematics say that the RTC crystal X2 is a NX3215SA32768KHZ.

The crystal's data sheet says Frequency tolerance  -20 ... +20 ×10-6 @ +25°C

 3 weeks = 1814400 seconds.

so, your observations are pretty much expected.

hth

KnarfB

Well thanks Knarf. Is there any other work around for this issue ?

I don't use F2, but look for app notes like: AN2604 Application note STM32F101xx and STM32F103xx RTC calibration.

Besides, synchronisation with some external precise reference clock, GPS signal, ...  seems possible.

hth

KnarfB 

Use a more precise crystal or calibrate like @KnarfB said. Preferably both. I have a project where I measure the 512Hz RTC output with an accurate frequency counter and use that to calculate the required calibration values.
You can make the calculation iterative too and redo the calibration later to get better calibration values.
You can also use the time drift to calculate the calibration value too. If you know when you last synced your clock and know the current time you can calculate the calibration values too.

How to calibrate the RTC of the STM32F207ZG can be found in the reference manual.

Kudo posts if you have the same problem and kudo replies if the solution works.
Click "Accept as Solution" if a reply solved your problem. If no solution was posted please answer with your own.

Well i have not yet tried calibrating RTC, which i will do later. Your answer seems the possible way to get precise rtc clock and i have selected as an answer.

Thanks for your insight into RTC calibration.