I am testing on nRF5340-DK(0.11.0) with nrf connect sdk(v2.4.0).
And Measuring current consumption.
When I added GPIO (button) to the scan_adv sample, High current consumption.
What is the problem?
modified scan_adv sample
/* main.c - Application main entry point */
/*
* Copyright (c) 2015-2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/types.h>
#include <stddef.h>
#include <zephyr/sys/printk.h>
#include <zephyr/sys/util.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/hci.h>
#include <zephyr/drivers/gpio.h>
#define SW0_NODE DT_ALIAS(sw0)
#if !DT_NODE_HAS_STATUS(SW0_NODE, okay)
#error "Unsupported board: sw0 devicetree alias is not defined"
#endif
static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(SW0_NODE, gpios,
{0});
static struct gpio_callback button_cb_data;
static uint8_t mfg_data[] = { 0xff, 0xff, 0x00 };
static const struct bt_data ad[] = {
BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, 3),
};
static void scan_cb(const bt_addr_le_t *addr, int8_t rssi, uint8_t adv_type,
struct net_buf_simple *buf)
{
mfg_data[2]++;
}
int main(void)
{
struct bt_le_scan_param scan_param = {
.type = BT_HCI_LE_SCAN_PASSIVE,
.options = BT_LE_SCAN_OPT_NONE,
.interval = 0x0010,
.window = 0x0010,
};
int err;
#if 0
if (!gpio_is_ready_dt(&button)) {
return 0;
}
err = gpio_pin_configure_dt(&button, GPIO_INPUT);
if (err != 0) {
return 0;
}
err = gpio_pin_interrupt_configure_dt(&button,
GPIO_INT_EDGE_BOTH/*GPIO_INT_EDGE_TO_ACTIVE*/);
if (err != 0) {
return 0;
}
#endif
printk("Starting Scanner/Advertiser Demo\n");
/* Initialize the Bluetooth Subsystem */
err = bt_enable(NULL);
if (err) {
printk("Bluetooth init failed (err %d)\n", err);
return 0;
}
printk("Bluetooth initialized\n");
err = bt_le_scan_start(&scan_param, scan_cb);
if (err) {
printk("Starting scanning failed (err %d)\n", err);
return 0;
}
do {
k_sleep(K_MSEC(400));
#if 0
/* Start advertising */
err = bt_le_adv_start(BT_LE_ADV_NCONN, ad, ARRAY_SIZE(ad),
NULL, 0);
if (err) {
printk("Advertising failed to start (err %d)\n", err);
return 0;
}
k_sleep(K_MSEC(400));
err = bt_le_adv_stop();
if (err) {
printk("Advertising failed to stop (err %d)\n", err);
return 0;
}
#endif
} while (1);
return 0;
}
GPIO disabled(3.62mA average)
GPIO enabled (3.99mA average)