RTC自动唤醒功能配置代码如下:
void RTC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
//allow access to rtc
PWR_RTCAccessCmd(ENABLE);
//RESET RTC Domain
RCC_RTCResetCmd(ENABLE);
RCC_RTCResetCmd(DISABLE);
//LSE enable 32.768k
RCC_LSEConfig(RCC_LSE_ON);
//wait till LSE is ready
while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
{}
//rtc clock select
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
//enable rtc clock
RCC_RTCCLKCmd(ENABLE);
// wait for rtc APB registers synchronisation
RTC_WaitForSynchro();
//EXIT Config
EXTI_ClearITPendingBit(EXTI_Line20);
EXTI_InitStructure.EXTI_Line = EXTI_Line20;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
//enable the rtc wakeup interrupt
NVIC_InitStructure.NVIC_IRQChannel = RTC_WKUP_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//rtc wakeup interrupt generation:clock source:RTCDiv_16,
//wakeup time base:4s
RTC_WakeUpClockConfig(RTC_WakeUpClock_CK_SPRE_16bits);
RTC_SetWakeUpCounter(10);
//enable the wakeup interrupt
RTC_ITConfig(RTC_IT_WUT, ENABLE);
}
|