Nucleo F401RE - 中断不工作

Nucleo F401RE - Interrupt not working

我的 Nucleo F401RE 有问题:当我试图通过更改 PA9 上的值来触发中断时,没有任何反应:(

我的代码:

void EXTI_Config(){

    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA,EXTI_PinSource6);
    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA,EXTI_PinSource7);
    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA,EXTI_PinSource8);
    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA,EXTI_PinSource9);
    EXTI_InitTypeDef buttonEXTI;
    EXTI_StructInit(&buttonEXTI);
    buttonEXTI.EXTI_Line = 0x1E0;
    buttonEXTI.EXTI_Mode = EXTI_Mode_Interrupt;
    buttonEXTI.EXTI_Trigger = EXTI_Trigger_Rising;
    buttonEXTI.EXTI_LineCmd = ENABLE;
    EXTI_Init(&buttonEXTI);

    NVIC_InitTypeDef buttonNVIC;

    buttonNVIC.NVIC_IRQChannel = EXTI9_5_IRQn;
    buttonNVIC.NVIC_IRQChannelPreemptionPriority = 1;
    buttonNVIC.NVIC_IRQChannelSubPriority = 0;
    buttonNVIC.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&buttonNVIC);

    EXTI_ClearFlag(0x1E0);
}

void EXTI9_5_IRQHandler(){
    if(EXTI_GetFlagStatus(EXTI_Line6)==SET){ //works
        EXTI_ClearITPendingBit(EXTI_Line6);
        if (mode==0&&isTimeSet){
            mode=1;
        } else if(mode==1){
            mode=2;
        } else {
            mode=1;
        }
    } else if (EXTI_GetFlagStatus(EXTI_Line7)==SET){ //works
        EXTI_ClearITPendingBit(EXTI_Line7);
        changeValue=2;
    } else if (EXTI_GetFlagStatus(EXTI_Line8)==SET){ //works
        EXTI_ClearITPendingBit(EXTI_Line8);
        changeValue=1;
    } else if (EXTI_GetFlagStatus(EXTI_Line9)==SET){ //don't work :(
        EXTI_ClearITPendingBit(EXTI_Line9);
        settingsApplied=1;
    }
}

所有其他中断都像魅力一样工作,但这个 - 不要。在电路板的示意图中,此引脚未插入,所以我不知道为什么会这样:(

我想问题出在下一行

buttonEXTI.EXTI_Line = 0x1E0;

你的掩码必须是 0x03C0

为避免类似错误您可以使用以下方法:

buttonEXTI.EXTI_Line = EXTI_Line6 | EXTI_Line7 | EXTI_Line8 | EXTI_Line9;