GPIOTE Interrupt events vs PORT event

GPIOTE has higher current consumption than port events. We are trying yo use PORT events to detect GPIO inputs with buttons. But we are not successful, is there any example available for this? We are using this code but callback does not trigger at all instead nRF52840 keeps rebooting each time button is pressed:

#include <zephyr/kernel.h>
#include <zephyr/sys/printk.h>
#include <zephyr/device.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <zephyr/sys/printk.h>
//#include <zephyr/drivers/gpio.h>
#include <zephyr/device.h>
#include <zephyr/pm/pm.h>
#include <zephyr/pm/device.h>
#include <zephyr/pm/policy.h>
#include <hal/nrf_gpio.h> 
#include <hal/nrf_gpiote.h>


/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS   5000  // 5 seconds

void GPIOTE_IRQHandler(void)
{
    // Handle the PORT event
	//printk("GPIOTE_IRQHandler");
    
    // Check if the event is triggered by any of the configured pins
    if (NRF_GPIO->IN & (1 << 6))
    {
        // Handle event for PIN_P0_06
        // Clear event
        //nrf_gpio_pin_toggle(13);
        NRF_GPIOTE->EVENTS_PORT = 0;
        //printk("BUTTON_0\n");
    }
    if (NRF_GPIO->IN & (1 << 7))
    {
        // Handle event for PIN_P0_07
        // Clear event
         //nrf_gpio_pin_toggle(30);
        NRF_GPIOTE->EVENTS_PORT = 0;
        //printk("BUTTON_1\n");
    }
    if (NRF_P1->IN & (1 << 4))
    {
        // Handle event for PIN_P1_04
        // Clear event
         //nrf_gpio_pin_toggle(42);
        NRF_GPIOTE->EVENTS_PORT = 0;
        //printk("BUTTON_2\n");
    }
    if (NRF_P1->IN & (1 << 11))
    {
        // Handle event for PIN_P1_11
        // Clear event
        // nrf_gpio_pin_toggle(17);
        NRF_GPIOTE->EVENTS_PORT = 0;
        //printk("BUTTON_3\n");
    }
}

int main(void)
{
    /*light sensor pins*/
		nrf_gpio_cfg_output(NRF_GPIO_PIN_MAP(0, 28));
		nrf_gpio_pin_clear(NRF_GPIO_PIN_MAP(0, 28));

		nrf_gpio_cfg_output(NRF_GPIO_PIN_MAP(0, 3));
		nrf_gpio_pin_clear(NRF_GPIO_PIN_MAP(0, 3));

		/*SPI and CAN BUS pins*/

		nrf_gpio_cfg_output(NRF_GPIO_PIN_MAP(1, 15));
		nrf_gpio_pin_clear(NRF_GPIO_PIN_MAP(1, 15));

		nrf_gpio_cfg_output(NRF_GPIO_PIN_MAP(1, 14));
		nrf_gpio_pin_clear(NRF_GPIO_PIN_MAP(1, 14));

		nrf_gpio_cfg_output(NRF_GPIO_PIN_MAP(1, 13));
		nrf_gpio_pin_clear(NRF_GPIO_PIN_MAP(1, 13));

		nrf_gpio_cfg_output(NRF_GPIO_PIN_MAP(1, 12));
		nrf_gpio_pin_clear(NRF_GPIO_PIN_MAP(1, 12));

		nrf_gpio_cfg_output(NRF_GPIO_PIN_MAP(1, 3));
		nrf_gpio_pin_clear(NRF_GPIO_PIN_MAP(1, 3));


        nrf_gpio_cfg_output(NRF_GPIO_PIN_MAP(0, 13));
        nrf_gpio_pin_clear(NRF_GPIO_PIN_MAP(0, 13));
        nrf_gpio_cfg_output(NRF_GPIO_PIN_MAP(0, 30));
        nrf_gpio_pin_clear(NRF_GPIO_PIN_MAP(0, 30));
        nrf_gpio_cfg_output(NRF_GPIO_PIN_MAP(1, 10));
        nrf_gpio_pin_clear(NRF_GPIO_PIN_MAP(1, 10));
        nrf_gpio_cfg_output(NRF_GPIO_PIN_MAP(1, 16));
        nrf_gpio_pin_clear(NRF_GPIO_PIN_MAP(1, 16));

        nrf_gpio_cfg_output(NRF_GPIO_PIN_MAP(0, 17));
        nrf_gpio_pin_clear(NRF_GPIO_PIN_MAP(0, 17));
        nrf_gpio_cfg_output(NRF_GPIO_PIN_MAP(1, 9));
        nrf_gpio_pin_clear(NRF_GPIO_PIN_MAP(1, 9));


     nrf_gpio_cfg_input(NRF_GPIO_PIN_MAP(0, 6), NRF_GPIO_PIN_PULLUP);
     nrf_gpio_cfg_input(NRF_GPIO_PIN_MAP(0, 7), NRF_GPIO_PIN_PULLUP);
     nrf_gpio_cfg_input(NRF_GPIO_PIN_MAP(1, 11), NRF_GPIO_PIN_PULLUP);
     nrf_gpio_cfg_input(NRF_GPIO_PIN_MAP(1, 4), NRF_GPIO_PIN_PULLUP);
     
    nrf_gpio_cfg_sense_set(6, NRF_GPIO_PIN_SENSE_LOW);
	nrf_gpio_cfg_sense_set(7, NRF_GPIO_PIN_SENSE_LOW);
	nrf_gpio_cfg_sense_set(43, NRF_GPIO_PIN_SENSE_LOW);
	nrf_gpio_cfg_sense_set(36, NRF_GPIO_PIN_SENSE_LOW);

    
	NRF_GPIOTE->INTENCLR = 0xFFFFFFFF;
	NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_PORT_Msk;
	NVIC_ClearPendingIRQ(GPIOTE_IRQn);
	NVIC_EnableIRQ(GPIOTE_IRQn);


    while(1)
    {
        k_sleep(K_MSEC(5000));
        printk("counter\n");
    }
    //k_sleep(K_FOREVER);
}

counter
*** Booting Zephyr OS build v3.3.99-ncs1-1 ***
*** Booting Zephyr OS build v3.3.99-ncs1-1 ***
*** Booting Zephyr OS build v3.3.99-ncs1-1 ***
*** Bo******* Booting Zephyr OS build v3.3.99-ncs1-1 ***
*** Booting Zephyr OS build v3.3.99-nc*** Booting Zephyr OS build v3.3.99-ncs1-1 ***
*** Booting Zephyr OS build v3.3.99-ncs1-1 ***
*** Booting Zephyr OS build v3.3.99-ncs1-1 ***
*** Booting Zephyr OS build v3.3.99-ncs1-1 ***
*** Booting Zephyr OS build v3.3.99-ncs1-1 ***

Parents Reply Children
No Data
Related