2011-11-22 09:53 AM
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 Khzvoid 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 }2011-11-22 11:35 AM
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();2011-11-25 02:02 AM
2011-11-25 06:15 AM
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.