This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

GPIO Interrupt not triggered

I am trying to set up a button interrupt by adding the following functions:

void button_interrupt_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
    nrf_gpio_pin_toggle(LED_4);
}

void button4_config()
{
    nrf_drv_gpiote_in_config_t config;
    memset(&config, 0, sizeof(nrf_drv_gpiote_in_config_t));
    config.sense = NRF_GPIOTE_POLARITY_HITOLO;
    config.pull = NRF_GPIO_PIN_NOPULL;
    config.hi_accuracy = false;
    config.is_watcher = false;
    
    nrf_drv_gpiote_in_init(BUTTON_4, &config, button_interrupt_handler);
    nrf_drv_gpiote_in_event_enable(BUTTON_4, true);
    
}
int main(void)
{
    // ...
    button4_config();
    // ...
}

When I tried to press the button, my interrupt is never called. Not even once.

Thinking that maybe the problem is because I was using BUTTON_4, I have also tried to replace it with pin 29 and use an external button. That doesn't work either.

What could I be missing?

Parents
  • I can't see that you are calling nrf_drv_gpiote_init() anywhere

    Edit 1: Try this:

    void button_interrupt_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
    {
        nrf_gpio_pin_toggle(LED_4);
    }
    
    static void button4_config()
    {
        nrf_drv_gpiote_in_config_t config;
        memset(&config, 0, sizeof(nrf_drv_gpiote_in_config_t));
        config.sense = NRF_GPIOTE_POLARITY_HITOLO;
        config.pull = NRF_GPIO_PIN_PULLUP;
        config.hi_accuracy = false;
        config.is_watcher = false;
    
        nrf_drv_gpiote_in_init(BUTTON_4, &config, button_interrupt_handler);
        nrf_drv_gpiote_in_event_enable(BUTTON_4, true);
    
    }
    
    /**
     * @brief Function for application main entry.
     */
    int main(void)
    {
        ret_code_t err_code;
    
        nrf_gpio_cfg_output(LED_4);
            
        err_code = nrf_drv_gpiote_init();
        APP_ERROR_CHECK(err_code);
    
        button4_config();
    
        while (true)
        {
        }
    }
    
  • My sincere apology, Petter. I was tangled up with a lot of deadline soon after our last discussion, and replying to you slipped out of my mind.

    What I meant by overwriting the button behavior is replacing the behavior bsp_init() programmed with my own.

Reply Children
No Data
Related