采用外部晶振的RTC部分配置代码:
- /* Enable the PWR clock */
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
- /* Allow access to RTC */
- PWR_BackupAccessCmd(ENABLE);
- /* Enable the LSE OSC */
- RCC_LSEConfig(RCC_LSE_ON);
-
- /* Wait till LSE is ready */
- do{
- tick++;
- }while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET && tick < 20000);
- tick = 0;
- /* Select the RTC Clock Source */
- RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
- /* Enable the RTC Clock */
- RCC_RTCCLKCmd(ENABLE);
-
- RTC_StructInit(&RTC_InitStructure);
- RTC_Init(&RTC_InitStructure);
-
- /* Wait for RTC APB registers synchronisation */
- RTC_WaitForSynchro();
|