STM32外部中断保持触发

时间:2015-03-19 13:13:21

标签: c triggers interrupt stm32 freertos

我正在尝试使用带有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);
    }
}

1 个答案:

答案 0 :(得分:1)

我发现了一个额外的编译器警告错误:

void GPIO_EXTILineConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource);

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

GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource13);