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

NRF5340 GPIO Interrupt and low power problem.

Hi everyone.


 I am developing a product with nRF5340. But I found some problems with the power consumption of the device.
I'm not sure what I am doing wrong. 

Condition
When disable button Interrups :  ~5uA
When enable button interrups  :  ~100uA 



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

#include <stdio.h>
#include <init.h>
#include <power/power.h>
#include <hal/nrf_gpio.h>

#define BT_PORT		"GPIO_0"
#define LED_1 		28
#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)
{
	printk("Button pressed ^_^\n");

	if (pins & BIT(BUTTON_1)) 
	{
		printk("Button pressed BUTTON_1\n");
		gpio_pin_set_raw(gpio_0, LED_1, 1);
	}else if (pins & BIT(BUTTON_2)) 
	{
		printk("Button pressed BUTTON_2\n");
		gpio_pin_set_raw(gpio_0, LED_1, 0);
	}

}

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_EDGE_FALLING);
	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_EDGE_FALLING);
	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("OK:configure_button\n");
		
}

void main(void)
{
	int ret;

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

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

project config

CONFIG_GPIO=y

CONFIG_SYS_POWER_MANAGEMENT=y
CONFIG_DEVICE_POWER_MANAGEMENT=y

CONFIG_PM=y
CONFIG_PM_DEEP_SLEEP_STATES=y
CONFIG_PM_SLEEP_STATES=y
# Required to disable default behavior of deep sleep on timeout
CONFIG_PM_STATE_LOCK=y
CONFIG_PM_DEVICE=y

CONFIG_USE_SEGGER_RTT=n
CONFIG_RTT_CONSOLE=n
CONFIG_SERIAL=n
CONFIG_LOG=y
CONFIG_CONSOLE=n
CONFIG_BT_DEBUG_LOG=n
CONFIG_STDOUT_CONSOLE=n
CONFIG_PRINTK=n

Source Code:  Link Zephyr_OS_BUTTON

Board: NRF5340-DK

SDK: nRF Connect SDK V1.5.0

Parents Reply Children
Related