Skip to main content
Explorer II
April 26, 2024
Question

GPIO interrupt triggered incorrectly

  • April 26, 2024
  • 3 replies
  • 1959 views

I am using micro switches in my system with the GPIO EXTI. I would like to detect only the press of the switch, but the interrupt was triggered on both press and release of the switch. The interrupts were even triggered twice on each press and release.

Here is my configuration of the pin. PC9 on the STM32H563ZI board is used. The GPIO pin is set as below, and the EXTI LINE9 Interrupt is checked in the NVIC setting.

hchienti_0-1714113986504.png

And here is the code:

void HAL_GPIO_EXTI_Falling_Callback(uint16_t GPIO_Pin)

{

printf("%d\n", GPIO_Pin);

}

Does any one know what's happening and how to fix it?

    This topic has been closed for replies.

    3 replies

    Technical Moderator
    April 26, 2024

    You probably have the same problem with bouncing as described there, except that your switch goes to GND and the one there goes to VDD. You should think about debouncing, for which there are (almost) as many solutions as there are developers.

    Hope that helps?

    Regards
    /Peter

    hchientiAuthor
    Explorer II
    April 26, 2024

    Hi @Peter BENSCH ,

    Thanks for reply. I guess bouncing might be the reason why the press is detected twice. How about detecting both on pressing and releasing? Could this came from bouncing, too?

    Graduate
    April 26, 2024

    Yes, bouncing can activate any edge trigger on both, press and release of a button. Try to solve this issue first. The most common way to do it is by adding a small capacitor between GPIO line and ground or by adding a time delay after the first edge detection.
    If the button press logic is still reversed after solving the bouncing issue, you can simply change the falling edge detection to rising edge. This inverted logic issue might be because of how your button outputs a signal. There is a chance that it's connected to ground when released, and to +3.3V, when pressed.

    Technical Moderator
    April 26, 2024

    Yes.

    Graduate II
    April 27, 2024

    You can do software debounce of switches. See this video https://www.youtube.com/watch?v=o0qhmXR5LD0