STM32 rising and falling button interrupt detection

artsin picture artsin · Sep 19, 2014 · Viewed 17.2k times · Source

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?

Answer

ayhankorkmaz picture ayhankorkmaz · Oct 10, 2014

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.