STM32外部中断一直触发

STM32 external interrupt keeps triggering

我正在尝试将旋转编码器和按钮与 STM32F103 和 FreeRTOS 一起使用。 pin0 和 pin1 的外部中断工作正常,但按钮连接到 Pin13(EXTI15_10_IRQHandler),它会无故触发。 当然,我可以只使用 pin2 (EXTI2_IRQHandler) 到 4 或在不中断的情况下轮询按钮引脚,但我想知道这是什么原因。 我在这里错过了什么?

    // button
#define ROEN_BUTTON_GPIO        GPIOC
#define ROEN_BUTTON_PIN         GPIO_Pin_13

    // init method

    NVIC_InitTypeDef NVIC_InitStruct;
    EXTI_InitTypeDef EXTI_InitStruct;
    GPIO_InitTypeDef GPIO_InitStructure;
    GPIO_StructInit(&GPIO_InitStructure);

   /**
    * GPIO configuration
    * Configure pins as input w/ pullup
    */
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;  
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Pin = ROEN_BUTTON_PIN;      // Button
    GPIO_Init(ROEN_BUTTON_GPIO, &GPIO_InitStructure);

    /* Tell system that you will use PC13 for EXTI_Line13 */
    GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, EXTI_Line13);

    /* Enable interrupt */
    EXTI_InitStruct.EXTI_LineCmd = ENABLE;
    /* Interrupt mode */
    EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
    /* Triggers on rising and falling edge */
    EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling;
    /* PC13 is connected to EXTI_Line13 */
    EXTI_InitStruct.EXTI_Line    = EXTI_Line13;
    EXTI_Init(&EXTI_InitStruct);


    /* Enable interrupt */
    NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
    NVIC_InitStruct.NVIC_IRQChannel = EXTI15_10_IRQn;
    /* Set priority */
    NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0x03;
    /* Add to NVIC */
    NVIC_Init(&NVIC_InitStruct);


/* Handle PC13 interrupt */
void EXTI15_10_IRQHandler(void) {
    /* Make sure that interrupt flag is set */
    if (EXTI_GetITStatus(EXTI_Line13) != RESET) {
        /* Clear interrupt flag */
        EXTI_ClearITPendingBit(EXTI_Line13);
    }
}

我发现错误并带有额外的编译器警告:

void GPIO_EXTILineConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource);

我为 GPIO_PinSource 使用了错误的宏,必须是

GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource13);