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)
        {
        }
    }
    
  • FormerMember
    0 FormerMember in reply to Petter Myhre

    The easiest way is to just change the number of buttons and LEDs defined in pca10028.h.

    If you want to keep pca10028.h unmodified, you can do the following:

    1. Copy pca10028.h and create a new pca10028 board file: my_board.h

    2. Change the number of buttons/LEDs.

    3. In the top of my_board.h, change the define to f.ex:

      #ifndef MY_BOARD_H #define MY_BOARD_H

    4. Add my_board.h to the list of boards in boards.h (named f.ex: BOARD_MY_BOARD)

    5. In project ->options for target -> C/C++ -> "define": replace BOARD_PCA10028 with BOARD_MY_BOARD

Reply
  • FormerMember
    0 FormerMember in reply to Petter Myhre

    The easiest way is to just change the number of buttons and LEDs defined in pca10028.h.

    If you want to keep pca10028.h unmodified, you can do the following:

    1. Copy pca10028.h and create a new pca10028 board file: my_board.h

    2. Change the number of buttons/LEDs.

    3. In the top of my_board.h, change the define to f.ex:

      #ifndef MY_BOARD_H #define MY_BOARD_H

    4. Add my_board.h to the list of boards in boards.h (named f.ex: BOARD_MY_BOARD)

    5. In project ->options for target -> C/C++ -> "define": replace BOARD_PCA10028 with BOARD_MY_BOARD

Children
No Data
Related