cancel
Showing results for 
Search instead for 
Did you mean: 

RTC WaitForSynchro

Posted on May 31, 2011 at 10:28

hi all,

I'm using a RTC (for the first time!). During the RTC_Configuration function, execution stops in RTC_WaitForSynchro() call.

void RTC_Configuration(void)

{

  RCC_LSICmd(ENABLE);

  while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET);

  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);

  RCC_RTCCLKCmd(ENABLE);

  RTC_WaitForSynchro();///////////////////////////////////stops here!

  RTC_WaitForLastTask();

  RTC_ITConfig(RTC_IT_SEC, ENABLE);

  RTC_WaitForLastTask();

  RTC_SetPrescaler(0);

  RTC_WaitForLastTask();

}

void RCC_Configuration(void)

{                                                       

  RCC_DeInit();

  RCC_HSEConfig(RCC_HSE_ON);

  if(RCC_WaitForHSEStartUp() == SUCCESS)

  {

    FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

    FLASH_SetLatency(FLASH_Latency_2);

    RCC_HCLKConfig(RCC_SYSCLK_Div1);

    RCC_PCLK2Config(RCC_HCLK_Div1);

    RCC_PCLK1Config(RCC_HCLK_Div2);

    RCC_PLLConfig(RCC_PLLSource_HSE_Div2, RCC_PLLMul_9);

    RCC_PLLCmd(ENABLE);

    while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);

    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

    while(RCC_GetSYSCLKSource() != 0x08);

  }

}

void NVIC_Configuration(void)

{

  NVIC_InitTypeDef NVIC_InitStructure;

  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);  

  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

  NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQChannel;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

}

int main(void)

{

  NVIC_Configuration();

  RCC_Configuration();

  RTC_Configuration();

  while (1);

}

thanks all

jerry

3 REPLIES 3
Posted on May 31, 2011 at 18:58

I think you'll need the following prior to RCC_RTCCLKConfig

  /* Enable the PWR and BKP Clocks */

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

  PWR_BackupAccessCmd(ENABLE);                        /* Allow access to BKP Domain */

  BKP_DeInit();                                                        /* Reset Backup Domain */

You probably want to set up the prescaler to a more valid figure, if you don't want ''1 second'' interrupts to occur at 40KHz

RTC_SetPrescaler(40000);

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on June 01, 2011 at 11:41

thanks Clive,

yesterday I found this solution, but it's not clear for me the reason!

I need only a RTC@20KHz (prescaler=1, so LSI/(1+1)=20KHz). Why are PWR and BKP needed???

thank for help

jerry

Posted on June 01, 2011 at 13:32

Why are PWR and BKP needed???

 

 

Because the way the units are powered, and protected across the reset. From the Reference Manual we have the specific cite :

5.1 BKP introduction

The backup registers are forty two 16-bit registers for storing 84 bytes of user application data. They are implemented in the backup domain that remains powered on by VBAT when the VDD power is switched off. They are not reset when the device wakes up from Standby mode or by a system reset or power reset.

In addition, the BKP control registers are used to manage the Tamper detection feature and RTC calibration.

After reset, access to the Backup registers and RTC is disabled and the Backup domain (BKP) is protected against possible parasitic write access. To enable access to the Backup registers and the RTC, proceed as follows:

�? enable the power and backup interface clocks by setting the PWREN and BKPEN bits in the RCC_APB1ENR register

�? set the DBP bit the Power Control Register (PWR_CR) to enable access to the Backup registers and RTC

There may be additional references, but this one sticks, and is on point.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..