cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F100 RTC issue

haykgh
Associate
Posted on September 19, 2013 at 15:57

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

#stm32f10x-rtc
2 REPLIES 2
damh
Associate II
Posted on September 19, 2013 at 17:00

We have the synchro-command at the end of the config. Rest is equal.

damh
Associate II
Posted on September 19, 2013 at 17:04

You probably need this in else-path, too:

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

  PWR_BackupAccessCmd(ENABLE);

I would enable IT-Config after synchro.