two interupts on same gpiote with two different pins nrf5340

hello,

i am using sdk 2.4.0 with nrf5340 i want to enable two diffferents buttons with interupts without disabling the one interupt because i need these two button for different scenario i cant basically trun off one interupt while using other 

/* API Prototypes */
void gpio_init()
{

	nrfx_err_t err;

	// Connect GPIOTE_0 IRQ to nrfx_gpiote_irq_handler 
	IRQ_CONNECT(DT_IRQN(DT_NODELABEL(gpiote)),
				DT_IRQ(DT_NODELABEL(gpiote), priority),
				nrfx_isr, nrfx_gpiote_irq_handler, 0);



	err = nrfx_gpiote_init(0);
	if (err != NRFX_SUCCESS)
	{
		// LOG_ERR("nrfx_gpiote_init error: %08x", err);
		return;
	}
nrfx_gpiote_in_config_t const mode_in_config = {
		.sense = NRF_GPIOTE_POLARITY_HITOLO,
		.pull = NRF_GPIO_PIN_NOPULL,
		.is_watcher = false,
		.hi_accuracy = true,
		.skip_gpio_setup = false,
	};

	nrfx_gpiote_in_config_t const in_config = {
		.sense = NRF_GPIOTE_POLARITY_HITOLO,
		.pull = NRF_GPIO_PIN_NOPULL,
		.is_watcher = false,
		.hi_accuracy = true,
		.skip_gpio_setup = false,
	};

	
/*	err = nrfx_gpiote_in_init(BUTTON_1_Pin, &mode_in_config, mode_button_handler);
	if (err != NRFX_SUCCESS)
	{
		 printf("nrfx_gpiote_in_init error 111111: %08x", err);
		return;
	}
	nrfx_gpiote_in_event_enable(BUTTON_1_Pin, true);*/
		err = nrfx_gpiote_in_init(BUTTON_2_Pin, &in_config, button_handler);
	if (err != NRFX_SUCCESS)
	{
		 printf("nrfx_gpiote_in_init error 2222222: %08x", err);
		return;
	}

nrfx_gpiote_in_event_enable(BUTTON_2_Pin, true);
	
	
}

i am getting error nrfx_gpiote_in_init error: 0bad0002 while initilaising second interupt

regards

manikandan 

Parents Reply Children
  • That suggests you have used up all 8 GPIOTE channels. A solution is to GPIOTE PORT events to detect the button interrupts. This is done by setting the .hi_accuracy flag to 'False'.

  • hi,thanks for the reply if i set that to flag to flase button interupts were not detected this is how i am doing it

    #define BUTTON_2_Pin		43//_PINNUM(1, 11)	//B20(P1.11)
    static void button_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
    {
    
    	if (action == NRF_GPIOTE_POLARITY_LOTOHI && pin == BUTTON_2_Pin)
    	{
    	//	printk("MY HANDLING\n");
    		
    	}
    }
    /* API Prototypes */
    void gpio_init()
    {
    
    	nrfx_err_t err;
    
    	/* Connect GPIOTE_0 IRQ to nrfx_gpiote_irq_handler */
    	IRQ_CONNECT(DT_IRQN(DT_NODELABEL(gpiote)),
    				DT_IRQ(DT_NODELABEL(gpiote), priority),
    				nrfx_isr, nrfx_gpiote_irq_handler, 0);
    
    	/* Initialize GPIOTE (the interrupt priority passed as the parameter
    	 * here is ignored, see nrfx_glue.h).
    	 */
    	err = nrfx_gpiote_init(0);
    	if (err != NRFX_SUCCESS)
    	{
    		// LOG_ERR("nrfx_gpiote_init error: %08x", err);
    		return;
    	}
    
    	nrfx_gpiote_in_config_t const in_config = {
    		.sense = NRF_GPIOTE_POLARITY_LOTOHI,
    		.pull = NRF_GPIO_PIN_PULLUP,
    		.is_watcher = false,
    		.hi_accuracy = false,
    		.skip_gpio_setup = false,
    	};
    
    	/* Initialize input pin to generate event on high to low transition
    	 * (falling edge) and call button_handler()
    	 */
    	err = nrfx_gpiote_in_init(BUTTON_2_Pin, &in_config, button_handler);
    	if (err != NRFX_SUCCESS)
    	{
    		// LOG_ERR("nrfx_gpiote_in_init error: %08x", err);
    		return;
    	}
    
    	nrfx_gpiote_in_event_enable(BUTTON_2_Pin, true);
    }
    
    

    regards

    manikandan v

  • I don't see any obvious errors in the code. Please try to debug your application in VS code and see if P1.11 becomes configured correctly after  the nrfx_gpiote_in_init() function has been run.

    It should look like this:

Related