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

Why can't I add more that 4 input signals?

I have12 input pins to my application. But the code fails when I try to add the fifth button.

Is there a limit to how many input signals I can add?

static void gpio_inputs_init(void)
{
	uint32_t err_code;

	if (!nrf_drv_gpiote_is_init())
	{
		err_code = nrf_drv_gpiote_init();
		APP_ERROR_CHECK(err_code);
	}

	setup_button(PIN_BUTTON_0);
	setup_button(PIN_BUTTON_1);
	setup_button(PIN_BUTTON_2);
	setup_button(PIN_BUTTON_3);
	setup_button(PIN_BUTTON_4);
	setup_button(PIN_BUTTON_5);
	setup_button(PIN_BUTTON_6);
	setup_button(PIN_BUTTON_7);
	setup_button(PIN_BUTTON_8);
	setup_button(PIN_BUTTON_9);
	setup_button(PIN_BUTTON_CLEAR);
	setup_button(PIN_BUTTON_OK);
}

static void setup_button(nrf_drv_gpiote_pin_t pin)
{
	uint32_t err_code;
	nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(false);
	in_config.pull = NRF_GPIO_PIN_PULLUP;

	err_code = nrf_drv_gpiote_in_init(pin, &in_config,
			in_pin_event_handler);
	APP_ERROR_CHECK(err_code);

	nrf_drv_gpiote_in_event_enable(pin, true);
}

I have single stepped my code and it is channel_port_alloc() that is called by nrf_drv_gpiote_in_init() that returns NO_CHANNELS:

ret_code_t nrf_drv_gpiote_in_init(nrf_drv_gpiote_pin_t pin,
                                  nrf_drv_gpiote_in_config_t const * p_config,
                                  nrf_drv_gpiote_evt_handler_t evt_handler)
{
    ASSERT(pin < NUMBER_OF_PINS);
    ret_code_t result = NRF_SUCCESS;
    /* Only one GPIOTE channel can be assigned to one physical pin. */
    if (pin_in_use_by_gpiote(pin))
    {
        result = NRF_ERROR_INVALID_STATE;
    }
    else
    {
        int8_t channel = channel_port_alloc(pin, evt_handler, p_config->hi_accuracy);  <---- **** This function gives the error ****
        if (channel != NO_CHANNELS)
        {
            if (p_config->is_watcher)
            {
                nrf_gpio_cfg_watcher(pin);
            }
            else
            {
                nrf_gpio_cfg_input(pin,p_config->pull);
            }

            if (p_config->hi_accuracy)
            {
                nrf_gpiote_event_configure(channel, pin,p_config->sense);
            }
            else
            {
                m_cb.port_handlers_pins[channel-NUMBER_OF_GPIO_TE] |= (p_config->sense)<< SENSE_FIELD_POS;
            }
        }
        else
        {
            result = NRF_ERROR_NO_MEM;
        }
    }
    return result;
}
Related