Multiple button interrupts

4 posts / 0 new
Last post
Cosmin
Offline
Last seen:4 years 11 months ago
Joined:2015-12-14 08:35
Multiple button interrupts

Hello Dialog,

I'm trying to make a BLE remote control and I want to use button interrupts. I'm using the following code:

GPIO_RegisterCallback( GPIO0_IRQn, app_button_press_cb );
GPIO_RegisterCallback( GPIO1_IRQn, app_button_press_cb );
GPIO_EnableIRQ( GPIO_PORT_0, GPIO_PIN_6, GPIO0_IRQn, true, true, 16 );
GPIO_EnableIRQ( GPIO_PORT_1, GPIO_PIN_1, GPIO1_IRQn, true, true, 16 );

This works fine. I press either buttons and it sends me to the interrupt function.

我的问题是,如果我佤邦nt to use more buttons (I have at least 6), the IRQn has only 5 GPIO interrupts (GPIO0_IRQn to GPIO4_IRQn), how do I enable more interrupts for more buttons?
If I put the GPIO0_IRQn on both enable functions, only the last button is enabled.

Thank you,
Cosmin.

Device:
MT_dialog
Offline
Last seen:2 months 1 week ago
Staff
Joined:2015-06-08 11:34
Hi Cosmin,

Hi Cosmin,

If you want more buttons in your device you can use a matrix scheme since the GPIO interrupts are limited, please check either the remote or the keyboard reference design for more information on how to implement this. Or another thing you can try is to, on interrupt (in the ISR) poll the specified pins (get the status of each pin).

Thanks MT_dialog

Ruchi Patel
Offline
Last seen:2 years 6 months ago
Joined:2017-03-29 10:50
Hello MT_dialog,

Hello MT_dialog,

I am facing same issue. I want to use 8 buttons. And the IRQn has only 5 GPIO interrupts (GPIO0_IRQn to GPIO4_IRQn), how do I enable more interrupts for more buttons?

You have mentioned this "on interrupt (in the ISR) poll the specified pins (get the status of each pin)" in your comment. Can you please explain this in details?

Also explain "the keyboard reference design" in details.

Thanks and Regards,
Ruchi

MT_dialog
Offline
Last seen:2 months 1 week ago
Staff
Joined:2015-06-08 11:34
Hi Ruchi Patel,

Hi Ruchi Patel,

As allready mentioned, the reference designs that are using multiple button are the keyboard and the remote control reference design, those reference designs include documents and application notes regarding their functionallity, so you can have a look at those documents and check details about their implementation (UM-B-009, UM-B-037). Regarding what i ve mentioned, if you dont want to implement a matrix scheme in order to have multiple buttons you can trigger a function when an interrupt occurs and read the corresponding port register in order to check which pins are high or low and that way you will be able to know which button is pressed.

Thanks MT_dialog