我做低功耗,用stm32f103的RTC闹钟唤醒待机,工作5s,待机5s,循环,但是待机唤醒后程序卡在重新给闹钟赋值处,如下图。不知道什么情况,求助各位大神
void Clock_ini_aaa(void)
{
//PWR_WakeUpPinCmd(DISABLE);
if(BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5) //判断保存在备份寄存器的RTC标志是否已经被配置过
{ //电源管理部分时钟开启
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
//使能后备寄存器访问
PWR_BackupAccessCmd(ENABLE);
BKP_ClearFlag();
BKP_DeInit();
//使能LSI
RCC_LSICmd(ENABLE);
//等待晶振启动
while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
{}
//设置时钟为内部晶振
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
RCC_RTCCLKCmd(ENABLE);
//等待RTC_CTL寄存器中的RSF位(寄存器同步标志)被硬件置1
RTC_WaitForSynchro();
RTC_WaitForLastTask();
//使能闹钟中断
RTC_ITConfig(RTC_IT_ALR, ENABLE);
RTC_WaitForLastTask();
RTC_ITConfig(RTC_IT_SEC, ENABLE);
RTC_WaitForLastTask();
//分频系数
RTC_SetPrescaler(32767); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32+1) */
RTC_WaitForLastTask();
//初始计数值
Time_Adjust();
//RTC_SetCounter(0);
RTC_WaitForLastTask();
BKP_WriteBackupRegister(BKP_DR1, 0xA5A5); //RTC设置后,将已配置标志写入备份数据寄存器
}
else
{
if(RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET) //检查是否掉电重启
{
printf("\r\n\n Power On Reset occurred....");
}
else if(RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET) //检查是否reset复位
{
printf("\r\n\n External Reset occurred....");
}
printf("\r\n No need to configure RTC....");
RTC_WaitForSynchro(); //等待RTC寄存器被同步
RTC_ITConfig(RTC_IT_SEC, ENABLE); //使能秒中断
RTC_WaitForLastTask();
RTC_ITConfig(RTC_IT_ALR, ENABLE); //naozhong
RTC_WaitForLastTask(); //等待写入完成
}
RCC_ClearFlag(); //清除复位标志
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/* Enable the RTC Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn; //配置外部中断源(秒中断)
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 7;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Enable the RTC Alarm Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = RTCAlarm_IRQn; //配置外部中断源(闹钟中断)
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//闹钟中断接到第17线外部中断
EXTI_ClearITPendingBit(EXTI_Line17);
EXTI_InitStructure.EXTI_Line = EXTI_Line17;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
void RTCAlarm_IRQHandler(void)
{
RTC_WaitForSynchro();
if(RTC_GetITStatus(RTC_IT_ALR) != RESET)
{
printf("mmmmmm");
EXTI_ClearITPendingBit(EXTI_Line17);
//RTC_WaitForLastTask();
RTC_WaitForLastTask();
if(PWR_GetFlagStatus(PWR_FLAG_WU) != RESET)
{
printf("111! ");
// 清除唤醒标志
PWR_ClearFlag(PWR_FLAG_WU);
RTC_WaitForLastTask();
}
RTC_ClearITPendingBit(RTC_IT_ALR);
RTC_WaitForLastTask();
RTC_Enter_StandbyMode(5);//5s后唤醒
}
}
|