cancel
Showing results for 
Search instead for 
Did you mean: 

Real Time on STM32F103RDT6

vagabondtt1503
Associate
Posted on November 22, 2011 at 18:53

Hi everybody,

I am using MCU STM32F103RBT6, i have a problem with real time clock.that is after reset MCU, real-time counter stand by 4~6 seconds and run. so, my real-time delay 4~6s after every reset MCU. I think real-time counter independent with reset MCU.

why is this issue?I hope to get everyone's help.Thank you very much.

P/S: This is my real time config, using CMSIS Library. Real time 's crystal : 32.768 Khz

void RTC_Configuration(void) {

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); // enableclock for Power interface

    PWR->CR |= 0x00000100; // enable access to RTC, BDC registers

    RCC_LSEConfig(RCC_LSE_ON); // enable LSE

    while ((RCC->BDCR & 0x02) == 0)

        ; // Wait for LSERDY = 1 (LSE is ready)

    RTC_EnterConfigMode();

    RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); // set RTC clock source

    RCC_RTCCLKCmd(ENABLE); // enable RTC clock

    RTC_WaitForLastTask();

    RTC->CRH |= 1 << 0;

    RTC_ExitConfigMode();

    RTC_WaitForLastTask(); // wait until write is finished

    PWR->CR &= ~0x00000100; // disable access to RTCregisters

   

}

3 REPLIES 3
Posted on November 22, 2011 at 20:35

You'll need different RTC initialization code paths based on the type of reset (power-on, standby, etc). For example there is clearly no point starting up and waiting for the LSE if it is already running. Take a look at some of the example code, it is really worth reviewing before coding randomly. Personally I find the STANDBY model to turn things off works significantly better than just killing the supply.

void RTC_Configuration(void)

{

  /* Check if the StandBy flag is set */

  if(PWR_GetFlagStatus(PWR_FLAG_SB) != RESET)

  {/* System resumed from STANDBY mode */

    /* Turn on led connected to GPIO_LED Pin7 */

    GPIO_SetBits(GPIO_LED, GPIO_Pin_7);

    /* Clear StandBy flag */

    PWR_ClearFlag(PWR_FLAG_SB);

    /* Wait for RTC APB registers synchronisation */

    RTC_WaitForSynchro();

    /* No need to configure the RTC as the RTC configuration(clock source, enable,

       prescaler,...) is kept after wake-up from STANDBY */

  }

  else

  {/* StandBy flag is not set */

    /* RTC clock source configuration ----------------------------------------*/

    /* Reset Backup Domain */

    BKP_DeInit();

    /* Enable LSE OSC */

    RCC_LSEConfig(RCC_LSE_ON);

    /* Wait till LSE is ready */

    while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)

    {

    }

    /* Select the RTC Clock Source */

    RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);

    /* Enable the RTC Clock */

    RCC_RTCCLKCmd(ENABLE);

    /* RTC configuration -----------------------------------------------------*/

    /* Wait for RTC APB registers synchronisation */

    RTC_WaitForSynchro();

    /* Set the RTC time base to 1s */

    RTC_SetPrescaler(32767);

    /* Wait until last write operation on RTC registers has finished */

    RTC_WaitForLastTask();

  }

}

  /* Enable PWR and BKP clock */

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

  /* Enable WKUP pin */

  PWR_WakeUpPinCmd(ENABLE);

  /* Allow access to BKP Domain */

  PWR_BackupAccessCmd(ENABLE);

  /* Configure RTC clock source and prescaler */

  RTC_Configuration();

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
vagabondtt1503
Associate
Posted on November 25, 2011 at 11:02

Thanks your reply. i tried to do variety of ways but my issue don't solved. :(

Posted on November 25, 2011 at 15:15

i tried to do variety of ways but my issue don't solved.

You'll have to break out the debugger and oscilloscope and chase down where that 4-6 seconds is going. It's not typical, but dealing with the RTC is a complex task, with a lot of interactions with how the system is shutdown, and restarted.

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