This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

nrf5340 GPIO interrupt of level

Hello Everyone,

When I debug the GPIO interrupt of nrf5340, the edge trigger can be normal, but it will be triggered all the time when the level is triggered. Does anyone have this problem?Below is my config and some code:

prj.conf

CONFIG_GPIO=y

# Config logger
CONFIG_LOG=y
CONFIG_USE_SEGGER_RTT=y
CONFIG_LOG_BACKEND_RTT=n
CONFIG_LOG_BACKEND_UART=y

main.c

#include <zephyr.h>
#include <sys/printk.h>
#include <drivers/gpio.h>


#define BT_PORT		"GPIO_0"

#define BUTTON_1	23
#define BUTTON_2	24

const struct device *gpio_0;

void button_pressed(const struct device *dev, struct gpio_callback *cb,
		    uint32_t pins)
{
 
    if (pins & BIT(BUTTON_1)) 
    {
      printk("Button1 is pressed!\n");
    }
    else if (pins & BIT(BUTTON_2)) 
    {
      printk("Button2 is pressed!\n");
    }

}

static void configure_button(void)
{
    int ret;
    static struct gpio_callback button_cb;

    gpio_0 = device_get_binding(BT_PORT);

    gpio_pin_configure(gpio_0, BUTTON_1, GPIO_INPUT | GPIO_PULL_UP);
    gpio_pin_configure(gpio_0, BUTTON_2, GPIO_INPUT | GPIO_PULL_UP);
    
    ret = gpio_pin_interrupt_configure(gpio_0, BUTTON_1, GPIO_INT_LEVEL_LOW);
    if (ret != 0) 
    {
      printk("Error %d: failed to configure interrupt pin %d\n" , ret,  BUTTON_1);
      return;
    }

    ret = gpio_pin_interrupt_configure(gpio_0, BUTTON_2, GPIO_INT_LEVEL_LOW);
    if (ret != 0) 
    {
      printk("Error %d: failed to configure interrupt pin %d\n" , ret,  BUTTON_2);
      return;
    }
    
    gpio_init_callback(&button_cb, button_pressed,
                       BIT(BUTTON_1) |
                       BIT(BUTTON_2) );
    
    gpio_add_callback(gpio_0, &button_cb);

    printk("button init ok\n");
		
}


void main(void)
{
    gpio_0 = device_get_binding(BT_PORT);

    if (gpio_0 == NULL) 
    {
      printk("Error: didn't find device port_0\n");
      return;
    }
    
    configure_button();

    while(1)
    {
       k_msleep(20000);
    }
}

Best regards

Pany

Related