Rtc sync with Remote clock (Gps)
Hi community,
If any face this issue earlier, please help me out.
I am working on stm32f417 board. Right now Am trying to sync rtc time with gps timing, but Am seeing drift in subseconds field of rtc.
Am programming the shift register of rtc every 10sec & reading rtc time in wakeup timer callback fun every one second.
Here is the my synchronzing code.
int8_t Sync_RTC_GPS()
{ static int sec_10 = 0; RTC_TimeTypeDef gTime; RTC_DateTypeDef gDate;HAL_RTC_GetTime(&hrtc, &gTime, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, &gDate, RTC_FORMAT_BIN);prev_ss = current_ss;
current_ss = gTime.SubSeconds; count++; sec_10++; /* * Skipping calculation of delta for the first time */if(count == 2)
{delta_time = current_ss - prev_ss; count = 1;if(sec_10 == 10){ sec_10 = 0; if(delta_time != 0) { if(delta_time > 0) {HAL_RTCEx_SetSynchroShift(&hrtc, RTC_SHIFTADD1S_RESET, delta_time );
}
else if(delta_time < 0) { HAL_RTCEx_SetSynchroShift(&hrtc, RTC_SHIFTADD1S_SET, 1 - delta_time); }return 1;
} else { /* * synchronized */ return 0; }} } return 0;}/*END OF Sync_RTC_GPS()*///================================================