GPIO interrupt triggered incorrectly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-25 11:55 PM
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.
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?
- Labels:
-
GPIO-EXTI
-
Interrupt
-
STM32H5 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-26 12:01 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-26 12:14 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-26 12:15 AM
Yes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-26 12:36 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-26 1:18 AM
Did you try some simple "standard" way to connect a switch ?
Try with a cap:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-04-26 5:51 PM
You can do software debounce of switches. See this video https://www.youtube.com/watch?v=o0qhmXR5LD0
TimerCallback tutorial! | UART and DMA Idle tutorial!
If you find my solution useful, please click the Accept as Solution so others see the solution.
