Search code examples
eventsstm32interruptions

STM32 rising and falling button interrupt detection


I have button interruption:

    void EXTI0_IRQHandler(void)
    {
        if (EXTI_GetITStatus(EXTI_Line0) != RESET){

            if (/* BUTTON IS RELEASED */) {
                /* do something */          
            }
            if (/* BUTTON IS PRESSED */) {
                /* do something else */
            }
        EXTI_ClearITPendingBit(EXTI_Line0);
        }

    }

Is there possibility to check this?


Solution

  • Yes it is possible. You must set EXTI Trigger method as EXTI_Trigger_Rising_Falling. So STM32 enter ISR when rising and Fallng edge. In ISR you can control GPIO pin.If GPIO Pın is set,it must be Rising Edge,Else it must be Falling edge.

    void EXTI0_IRQHandler(void)
    {
        if (EXTI_GetITStatus(EXTI_Line0) != RESET){
    
            if (PIN==1) {//Rising so pressed
                /* do something */          
            }
            if (PIN==0) {Falling so released
                /* do something else */
            }
        EXTI_ClearITPendingBit(EXTI_Line0);
        }
    
    }
    

    NOTE: Above behaves properly with pull-down connected to the button. With pull up, rising and falling will be inverted.