|
12.5p晶振启动时间比6P的长可能才是主要的原因
我的板上32.768K晶振(12.5P)也老是出现上电起振难的问题.看到楼主讲主换6P的,我找不到,后来想到也许是12.5P的晶振起动时所需时间要比6P的长,我对RTC的初始化作了一点改动... 这是KEIL RTC例程中的:
/******************************************************************************* * Function Name : RTC_Configuration * Description : Configures the RTC. * Input : None * Output : None * Return : None *******************************************************************************/ 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(); }
上上代码中的" /* Enable LSE */ RCC_LSEConfig(RCC_LSE_ON); /* Wait till LSE is ready */ while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) { } " 改为: u32 delay; do { /* delay about 10ms */ for(delay = 0;delay < 90000;delay++); /* Enable LSE */ RCC_LSEConfig(RCC_LSE_ON); }while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) /* Wait till LSE is ready */
后测试1000次以上都没有上电赶振难发现.但改回原来又好易发生. 大家也可以试试此法是否对你有用. |
|