How many interrupt pins we can enable in NRF52840?

Hi Everyone,

                I am using NRF52840 in my project and compiling my code using sdk 17.0.2. My application requires 7 interrupt pins to be enabled. However when I am enabling all the interrupts i get an error. I observed that the sdk is allowing only 4 interrupts to be enabled. If I enable the 5th pin, it gets an error. Is there any way I can increase the count of interrupts to be enabled??

The pins which I want to be enabled as interrupts are as follows:-

//INTERRUPTS


#define INTERRUPT_1 NRF_GPIO_PIN_MAP(0,19)
#define INTERRUPT_2 NRF_GPIO_PIN_MAP(0,29)
#define INTERRUPT_3 NRF_GPIO_PIN_MAP(1,2)
#define INTERRUPT_4 NRF_GPIO_PIN_MAP(1,7)
#define INTERRUPT_5 NRF_GPIO_PIN_MAP(1,8)
#define INTERRUPT_6  NRF_GPIO_PIN_MAP(1,15)
#define INTERRUPT_7  NRF_GPIO_PIN_MAP(0,31)

I am enabling them in the code as follows:-

void gpio_init(void)
{
    ret_code_t err_code;
    
    err_code = nrf_drv_gpiote_init();
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(false);// GPIOTE_CONFIG_IN_SENSE_HITOLO//GPIOTE_CONFIG_IN_SENSE_TOGGLE
    in_config.pull = NRF_GPIO_PIN_PULLUP;

    err_code = nrf_drv_gpiote_in_init(INTERRUPT_1, &in_config, in_pin_handler);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_gpiote_in_init(INTERRUPT_2, &in_config, in_pin_handler);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_gpiote_in_init(INTERRUPT_3, &in_config, in_pin_handler);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_gpiote_in_init(INTERRUPT_4, &in_config, in_pin_handler);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_gpiote_in_init(INTERRUPT_5, &in_config, in_pin_handler);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_gpiote_in_init(INTERRUPT_6, &in_config, in_pin_handler);
    APP_ERROR_CHECK(err_code);
	
	err_code = nrf_drv_gpiote_in_init(INTERRUPT_7, &in_config, in_pin_handler);
    APP_ERROR_CHECK(err_code);


     nrf_drv_gpiote_in_event_enable(INTERRUPT_1, true);
     nrf_drv_gpiote_in_event_enable(INTERRUPT_2, true);
     nrf_drv_gpiote_in_event_enable(INTERRUPT_3, true);
     nrf_drv_gpiote_in_event_enable(INTERRUPT_4, true);
     nrf_drv_gpiote_in_event_enable(INTERRUPT_5, true);
     nrf_drv_gpiote_in_event_enable(INTERRUPT_6, true);
     nrf_drv_gpiote_in_event_enable(INTERRUPT_7, true);
}

Please help me on how we can use more than 7 interrupts.

Thank you.

  • Hi,

    You configure the pins with GPIOTE_CONFIG_IN_SENSE_HITOLO(false);, and as you set false here that means you are not using GPIOTE. That could be OK, but in that case you need to adjust the number of low power events (whici is 4 by default in most applications). To do so, adjust GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS in sdk_config.h to a higher value (at least 7).

  • Hi  ,

                                   According to your suggestion I changed the config in sdk_config.h as below:-

    #ifndef NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS
    #define NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS      7 
    #endif

    Previously the value set was 1. But still was not able to enable the interrupts.

    Then I changed the configuration of pins from GPIOTE_CONFIG_IN_SENSE_HITOLO(false) to GPIOTE_CONFIG_IN_SENSE_HITOLO(true). Now I am not getting any errors. 

    Is this change ok?

  • Hi,

    sne_333 said:

                                   According to your suggestion I changed the config in sdk_config.h as below:-

    #ifndef NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS
    #define NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS      7 
    #endif

    As you are using the nrf_drv API you need to set the GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS and not the NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS, and then this should work.

    sne_333 said:

    Then I changed the configuration of pins from GPIOTE_CONFIG_IN_SENSE_HITOLO(false) to GPIOTE_CONFIG_IN_SENSE_HITOLO(true). Now I am not getting any errors. 

    Is this change ok?

    Yes, in most cases. When set to true, you are using GPIOTE instead of port event. The down side is a slightly higher power consumption (which may or may not be an issue for you). There are 8 GPIOTE channels on the nRF52840, so using 7 is no problem.

  • Thank you so much. Setting GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS to 7 resolved my issue. Now it is working even if I set GPIOTE_CONFIG_IN_SENSE_HITOLO(false).

Related