How to handle input from multiple buttons using one interrupt?

319 views Asked by At

I wonder how to make IRQ handler, which can react differently on pushing each button.

I'm thinking to do that in this way:

void EXTI9_5_IRQHandler(){
    if (EXTI_GetITStatus(EXTI_Line_5)){
        doThis();
    } else if (EXTI_GetITStatus(EXTI_Line_6)) {
        doThat();
    }
}

I don't know how to connect multiple buttons to one interrupt, and this is my worst problem :(

1

There are 1 answers

0
Guillaume Michel On BEST ANSWER

That is the principle. I am not too familiar with std peripherals, but I am wondering if EXTI_GetFlagStatus would be better in your case. Also don't forget to clear the interrupt flag.

Your code should look like:

void EXTI9_5_IRQHandler(){
    if (EXTI_GetITStatus(EXTI_Line_5)){
        EXTI_ClearFlag(EXTI_Line_5);
        doThis();
    } else if (EXTI_GetITStatus(EXTI_Line_6)) {
        EXTI_ClearFlag(EXTI_Line_6);
        doThat();
    }
}