本帖最后由 打小就不错 于 2022-2-22 19:35 编辑
RT.
我试过将两个中断,设置成两个中断处理函数,是正常的,两个端口产生中断有先后顺序(先后的时间没评估过,在1ms内或者更小吧)。
先说问题,当我将两个外部中断设置成同一个中断处理函数时,似乎有点不正常:当进入中断时,判断中断SR寄存器,两个中断口的中断状态都读到信息了【这样我就没办法判断,两个中断产生的先后顺序了】。
RCC_AHBPeriphClockCmd(RCC_AHBENR_GPIOA, ENABLE);
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//PA.2 use EXTI line 2
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource2);
EXTI_InitStructure.EXTI_Line = EXTI_Line2;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;//EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI2_3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//PA.15 use EXTI line 15
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource15);
EXTI_InitStructure.EXTI_Line = EXTI_Line15;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;//EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI2_3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
void EXTI2_3_IRQHandler(void)
{
if((EXTI_GetITStatus(EXTI_Line2) != RESET) && (EXTI_GetITStatus(EXTI_Line15) != RESET))
{
printf("EXTI2_3_IRQHandler Pin Error\n");
} EXTI_ClearFlag(EXTI_Line15);
EXTI_ClearFlag(EXTI_Line2);
}
刚学,求大神指点。
|