用的是Stm32f103vb开发板;
KEY1(PB10)和KEY2(PB11)分别触发两个中断,其中KEY1中断的优先级高于KEY2的优先级,
想通过实验验证当中断2程序运行时(LED3、4点亮)可以被中断1的程序抢断(LED1、2点亮);
可是接通实验板运行后按KEY2后LED3、4灯点亮,再按KEY1后无法实现抢断的功能;是我的优先级配置
出错了还是中断程序不对呢,请指教;以下是中断的程序;
void EXTI10_Config(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource10);
EXTI_InitStructure.EXTI_Line=EXTI_Line10;
EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd=ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel=EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void EXTI11_Config(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource11);
EXTI_InitStructure.EXTI_Line=EXTI_Line11;
EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd=ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel=EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void EXTI15_10_IRQHandler(void)
{
if (EXTI_GetITStatus(EXTI_Line10)!=RESET)
{
while(1)
{
LED1_ON;
LED2_ON;
LED3_OFF;
LED4_OFF;
EXTI_ClearITPendingBit(EXTI_Line10);
}
}
if (EXTI_GetITStatus(EXTI_Line11)!=RESET)
{
while(1)
{
LED1_OFF;
LED2_OFF;
LED3_ON;
LED4_ON;
EXTI_ClearITPendingBit(EXTI_Line11);
}
}
}
|