void StopRTCLSIMode(int count)
{
EXTI_InitTypeDef EXTI_InitStructure;
PWR_RTCAccessCmd(ENABLE);//Allow access to RTC
RCC_LSICmd(ENABLE);//LSI Enable
while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY)==RESET);//wait till LSI is ready
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);//RTC Clock Source Selection
RCC_RTCCLKCmd(ENABLE);//Enable RTC clock
RTC_WaitForSynchro();//wait for RTC APB registers synchronisation
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);
RTC_WakeUpCmd(DISABLE);//制止唤醒计数器
RTC_WakeUpClockConfig(RTC_WakeUpClock_RTCCLK_Div16);//唤醒时钟16分频
RTC_SetWakeUpCounter(count);//设置唤醒计数器
RTC_ITConfig(RTC_IT_WUT,EBANLE);//使能唤醒中止
RTC_WakeUpCmd(ENABLE);//使能唤醒计数器
}
//唤醒中止
void RTC_WKUP_IRQHandler(void)
{
if(RTC_GetITStatus(RTC_IT_WUT)!=RESET)
{
RTC_ClearITPendingBit(RTC_IT_WUT);
EXTI_ClearITPendingBit(EXTI_Line20);
Systeminit();
StopRTCLSIMode(2312)//~1S 再次初始化守时唤醒时刻
//从头初始化外设
isWKUP = 1;
}
}
在主函数中
int main(void)
{
//TO DO
//1.初始化守时唤醒
//2.进入低功耗形式
while(1)
{
if(isWKUP)
{
isWKUP = 0;
//TO DO 唤醒后干一些工作
StopRTCLSIMode(2312)//~1S 再次初始化守时唤醒时刻
//进入低功耗形式
}
}
}