AnsweredAssumed Answered

STM32F100 RTC issue

Question asked by ghaltaghchyan.hayk on Sep 19, 2013
Latest reply on Sep 19, 2013 by damh
Hi all,

I have trouble with RTC on STM32VLDISCOVERY board.
After initialization, when I'm calling RTC_WaitForLastTask() after RTC_SetCounter() function, the MCU falls into an infinite loop.

I can't get what is wrong.
Is this hardware issue, if yes is there any workaround?

My Code is :
void RTC_Configuration(void)
{
  /* Enable PWR and BKP clocks */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
  /* Allow access to BKP Domain */
  PWR_BackupAccessCmd(ENABLE);
  /* Reset Backup Domain */
  BKP_DeInit();
  /* Enable LSE */
  RCC_LSEConfig(RCC_LSE_ON);
  /* Wait till LSE is ready */
  while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET);
  /* Select LSE as RTC Clock Source */
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
  /* Enable RTC Clock */
  RCC_RTCCLKCmd(ENABLE);
  /* Wait for RTC registers synchronization */
  RTC_WaitForSynchro();
  /* Wait until last write operation on RTC registers has finished */
  RTC_WaitForLastTask();
  /* Enable the RTC Second */
  RTC_ITConfig(RTC_IT_SEC, ENABLE);
  /* Wait until last write operation on RTC registers has finished */
  RTC_WaitForLastTask();
  /* Set RTC prescaler: set RTC period to 1sec */
  RTC_SetPrescaler(32767); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */
  /* Wait until last write operation on RTC registers has finished */
  RTC_WaitForLastTask();
  /* Set RTC counter: set RTC counter to 0 */
  RTC_SetCounter(0);
  /* Wait until last write operation on RTC registers has finished */
  RTC_WaitForLastTask();
}

void main() {
  ....
  if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)
  {
    RTC_Configuration();
    BKP_WriteBackupRegister(BKP_DR1, 0xA5A5);
  }
  else
  {
    RTC_WaitForSynchro();
    RTC_ITConfig(RTC_IT_SEC, ENABLE);
    RTC_WaitForLastTask();
  }
  RCC_ClearFlag();  
  ....
  while(1) {
    ....
    RTC_WaitForLastTask();
    RTC_SetCounter(1379598788);
    RTC_WaitForLastTask();
    ....
  }
}


Thanks in advance.

Best Regards,
Hayk

Outcomes