Hi all,
this is my first topic on the forum, so please me in advance if I make some mistake.
As the subject suggests I have some trouble with the interrupts. In my project, I use a Nano 33 Ble board with several buttons (around 10) and I'd like to manage the buttons' states exploiting interrupts.
If I define a specific interrupt for each button everything goes right up to the first 8 interrupts. The 9th interrupt seems to not be triggered.
Is there a maximum number of attachable interrupts?
andrev2890:
I'd like to manage the buttons' states exploiting interrupts.
Using interrupts for buttons is not the best idea. Here is why
Buttons presses are slow compared to a many MHz microcontroller. Testing a button 10 times a second can be enough. This requires almost no effort at all.
Buttons create very fast pulses by a process called bouncing. You need to filter these pulses (called de-bouncing). Otherwise you will count button presses that are none. When you use interrupts you will get many interrupts and it is unnecessary hard to filter.
There are examples in the Arduino IDE and you can find libraries in the library manager as well.
Hi, Klaus_K thanks for your response.
I know about debouncing. Let consider button management using interrupts as an experiment.
Anyway, without considering for a while the source of the interrupts is there any reason that limits the number of interrupts to 8?
I'm trying to attach the interrupts to the corresponding gpios using the following code:
attachInterrupt(digitalPinToInterrupt(BUTTON_1), _btn1, CHANGE);
attachInterrupt(digitalPinToInterrupt(BUTTON_2), _btn2, CHANGE);
attachInterrupt(digitalPinToInterrupt(BUTTON_3), _btn3, CHANGE);
attachInterrupt(digitalPinToInterrupt(BUTTON_4), _btn4, CHANGE);
attachInterrupt(digitalPinToInterrupt(BUTTON_5), _btn5, CHANGE);
attachInterrupt(digitalPinToInterrupt(BUTTON_6), _btn6, CHANGE);
attachInterrupt(digitalPinToInterrupt(BUTTON_7), _btn7, CHANGE);
attachInterrupt(digitalPinToInterrupt(BUTTON_8), _btn7, CHANGE);
attachInterrupt(digitalPinToInterrupt(BUTTON_9), _btn9, CHANGE);
Have a look into the nRF52840 datasheet section
6.10 GPIOTE — GPIO tasks and events
The GPIO tasks and events (GPIOTE) module provides functionality for accessing GPIO pins using tasks and
events. Each GPIOTE channel can be assigned to one pin.
Instance GPIOTE Number of GPIOTE channels 8
There seems to be an alternative way of generating event on a port basis.
6.10.2 Port event
PORT is an event that can be generated from multiple input pins using the GPIO DETECT signal.
I do not know how you can make use of that using mbedOS/Arduino functions.