Is there a simple software code example how to configure an interrupt handler for a single GPIO-pin? I am using nRF51822 chip with softdevice S110 and the interrupt source is connected to pin P0.24.
Is there a simple software code example how to configure an interrupt handler for a single GPIO-pin? I am using nRF51822 chip with softdevice S110 and the interrupt source is connected to pin P0.24.
Hi Jarmo,
Most ble-* prefixed examples in the nRF51822 SDK uses a module called "app_button" which you can use to generate a pin-interrupt. See function "buttons_init" in ble_app_hids_mouse for instance.
This library also includes a simple debounce (or detection delay as it's called in the lib)
Best regards Håkon
Thanks, I checked the code. For me, it looks like it is using a timer to poll the pin. The code is as below (clipped). There is no hint about using interrupt, except the timer, or do I misunderstand?
// Configure pin.
nrf_gpio_cfg_input(p_btn->pin_no, p_btn->pull_cfg);
// Build GPIOTE user registration masks.
m_active_high_states_mask |= ((p_btn->active_high ? 1 : 0) << p_btn->pin_no);
m_active_low_states_mask |= ((p_btn->active_high ? 0 : 1) << p_btn->pin_no);
}
// Register button module as a GPIOTE user.
err_code = app_gpiote_user_register(&m_gpiote_user_id,
m_active_high_states_mask,
m_active_low_states_mask,
gpiote_event_handler);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
// Create polling timer.
return app_timer_create(&m_detection_delay_timer_id,
APP_TIMER_MODE_SINGLE_SHOT,
detection_delay_timeout_handler);
The library uses the timer for the "detection delay". The actual pin-interrupt occurs in "void GPIOTE_IRQHandler(void)" (app_gpiote.c), as he app-button lib registers itself as a GPIOTE-user in the init function.