本帖最后由 coderdd 于 2017-8-17 18:05 编辑
目前发现,用stm32f103开的外部中断。每次进入外中断后,我会先关闭外中断(因为这是摇晃,我只要它有唤醒功能即可,普通情况下不需要它一直外中断),等休眠前几秒再打开外中断,这样单片机就可以每次都可以唤醒。这都是正常的。但是,如果这个外中断在休眠前我没有开启,这导致每次进入休眠时单片机却休眠不了了!必须休眠前开启这个外中断才可以正常休眠,什么鬼??休眠和外中断有啥关系?
void EXTI9_5_IRQHandler(void)//B5摇晃,进入外中断后就关掉这个中断
{
led_status_flag=1;
if(EXTI_GetITStatus(EXTI_Line5)!= RESET)
{
free_to_halt_cout=0;
Close_Shake_INT();
}
EXTI_ClearITPendingBit(EXTI_Line5);
}
------------------------------------------------
Open_Shake_INT();//这一句不加上就进入不了休眠,什么情况??
MCU_Run_StopMode();//MCU休眠
--------------------------
void Close_Shake_INT()//关摇晃中断
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; //摇晃中断
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;
NVIC_Init(&NVIC_InitStructure);
}
void Open_Shake_INT()//打开摇晃中断
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
|