Skip to main content
Associate II
April 26, 2024
Question

GPIO interrupt triggered incorrectly

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.

6 replies

Peter BENSCH
ST 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

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
hchientiAuthor
Associate 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?

Associate II
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.

Peter BENSCH
ST Technical Moderator
April 26, 2024

Yes.

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Karl Yamashita
Principal
April 27, 2024

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

 

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source