2016-11-28 01:59 AM
Hi,
I'm using STM32L476RG microcontroller and I'm configuring the RTC to get the instant time value. I'm using LSE with 32,786 KHz as a clock source for my RTC . I have followed this application note () to set correctly the initialization process as well as the PREDIV_SYNCH and PREDIV_ASYNCH values (which are respectively in my case 0x00FF and 0x7F ) . However, when I let my application run for too long ( 24 Hours ) and then I check the RTC Time value , I found a gap of 10 seconds ( difference between my RTC time and the desktop time ). This difference is so huge for me because I'm working on medical app. Here's my Init function:&sharpdefine RTC_ASYNCH_PREDIV 0x7F&sharpdefine RTC_SYNCH_PREDIV 0x00FF BSP_RTC_Status Status= RTC_OK; /**** Configure the RTC peripheral ******************/ /* Configure RTC prescaler and RTC data registers */ /* RTC configured as follow: - Hour Format = Format 12 - Asynch Prediv = Value according to source clock - Synch Prediv = Value according to source clock - OutPut = Output Disable - OutPutPolarity = High Polarity - OutPutType = Open Drain */ __HAL_RTC_RESET_HANDLE_STATE(&RtcHandle); RtcHandle.Instance = RTC; RtcHandle.Init.HourFormat = RTC_HOURFORMAT_12; RtcHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV; RtcHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV; RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE; RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; if(HAL_RTC_Init(&RtcHandle)!= HAL_OK) { Status = RTC_ERROR; } __HAL_RTC_WRITEPROTECTION_DISABLE(&RtcHandle); RtcHandle.Instance->CR |= RTC_CR_BYPSHAD; /* Enable the write protection for RTC registers */ __HAL_RTC_WRITEPROTECTION_ENABLE(&RtcHandle);Any ideas please ? #rtc #l4 #time #stm322016-11-28 09:17 AM
This is around 115ppm. More than one would expect from a common 32kHz crystal, but not that much that couldn't be explained by poor design of the oscillator - improper burden capacitors, long traces imposing further parasitics. The oscillator circuit is a low-power one, and can be easily thrown wrong even by flux residues.
Review AN2867. Also, RTCs in most STM32 have ''fine tuning'' provisions, read the RTC chapter of RM. JW2016-11-29 01:05 AM
Hi Elliot,
As mentionned in the same application note that you mentioned AN4759, you should perform a dogital smooth calibration to compensate the RTC clock deviation which causes a time deviation. You would refer to following parts:- 1.4 Digital Smooth Calibration- 5 STM32L4 API and digital smooth calibrationapplication example -Hannibal-2016-11-30 06:32 AM
Thanks for both of you !
I will do the smooth calibration and hope that I will be back with good news :))2017-06-20 08:07 AM
a) disconnect debugger (or set DBGMCU_APB1FZR1 appropriate (DBG_RTC_STOP=0))
b) check, if your PC is the problem (most windows PCs without automatic RTC sync have this problem, difference of ~10-15s is normal)
c) check your ambient temperature (RTCs are working only well at ~20°C)