AnsweredAssumed Answered

RTC Time value

Question asked by Elliot on Nov 28, 2016
Latest reply on Jun 20, 2017 by damh
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 (link) 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:

#define RTC_ASYNCH_PREDIV  0x7F
#define 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 ?

Outcomes