MORE GPIOS AS EVENTS

Hi,

I am developing some application for that I want 12 pins as interrupt mode, but I can see only 8 pins can be configured.

Can anyone suggest me please.

Thanks, and regards.

  • Hi haakonsh,

    can you see at the right corner the err_code is LOCAL_ERR_CODE this is happening when nrf_drv_gpiote_in_init is called for the second time.

    Thanks for your reply.

  • You need to increase NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS to however many pins you want to use. As well as call nrfx_gpiote_in_event_enable() for each pin. 

    You can provide unique event handlers to each pin, you don't need to use a single event handler like 'port_event_handler'. 

    //Set 'NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS 2' in nrfx_config.h!
    
    
    void port_event_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
    {
        switch(pin)
        {
            case PIN_NUMBER_1:
                if(action == NRF_GPIOTE_POLARITY_HITOLO)
                {
                    // Do stuff
                }
                else if((action == NRF_GPIOTE_POLARITY_LOTOHI)
                {
                    // Do stuff
                }
                break;
            
            case PIN_NUMBER_2:
                if(action == NRF_GPIOTE_POLARITY_HITOLO)
                {
                    // Do stuff
                }
                else if((action == NRF_GPIOTE_POLARITY_LOTOHI)
                {
                    // Do stuff
                }
                break;
                
            default:
                // Do nothing, not interrested in any of the other pins port events
                break;
        }
    }
    
    uint32_t err_code;
    
    // Initialize GPIOTE module
    err_code = nrf_drv_gpiote_init();
    APP_ERROR_CHECK(err_code);
    
    nrfx_gpiote_in_config_t in_config;
    
    in_config.sense = NRF_GPIOTE_POLARITY_HITOLO;
    in_config.pull = NRF_GPIO_PIN_PULLUP;
    in_config.is_watcher = false;
    in_config.hi_accuracy = false;
    in_config.skip_gpio_setup = false;
    
    err_code = nrf_drv_gpiote_in_init(PIN_NUMBER_1, &in_config, port_event_handler);
    APP_ERROR_CHECK(err_code);
    
    err_code = nrf_drv_gpiote_in_init(PIN_NUMBER_2, &in_config, port_event_handler);
    APP_ERROR_CHECK(err_code);
    
    nrfx_gpiote_in_event_enable(PIN_NUMBER_1, false);
    nrfx_gpiote_in_event_enable(PIN_NUMBER_2, false);

  • Hi haakonsh,

    I will try this code and thank you so much for your continues support.

    Thanks and regards

    Ajmal

Related