Hello,
So, I have a working BLE project on the nRF52840 Dongle and I developed and debugged everything on the DevKit, using Zephyr/nRF Connect for VS Code. From there, I attempted to set up a separate thread that times-out after x seconds of advertising (if no connection is established) and turns off the device, as in the "system_off" sample:
pm_power_state_force((struct pm_state_info){PM_STATE_SOFT_OFF, 0, 0});
I also configured one of the DevKit's buttons to wake up / turn on the device (as in the "system_off" sample):
#include <hal/nrf_gpio.h> /* Configure to generate PORT event (wakeup) on button 1 press. */ nrf_gpio_cfg_input(DT_GPIO_PIN(DT_NODELABEL(button0), gpios), NRF_GPIO_PIN_PULLUP); nrf_gpio_cfg_sense_set(DT_GPIO_PIN(DT_NODELABEL(button0), gpios), NRF_GPIO_PIN_SENSE_LOW);
When I flashed and tested the functionality on the DevKit it worked perfectly fine, however, when I flashed and tried on the Dongle, pressing the button would not wake up the device. I figured out it might have to do with the library used for some reason, hal/nrf_gpio library does not seem to work on the Dongle ?? I managed to solve the problem configuring the button with the following code (regular drivers/gpio library):
#include <drivers/gpio.h> #define WAKEUP_BTN_ALIAS sw0 #define SW_NODE DT_ALIAS(WAKEUP_BTN_ALIAS) static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(SW_NODE, gpios, {0}); // Configure to generate PORT event (wakeup) on button press. gpio_pin_configure_dt(&button, GPIO_INPUT); gpio_pin_interrupt_configure_dt(&button, GPIO_INT_LOW_0);
This way it does work on both the DevKit AND the Dongle, however, I realized after a couple of days that the button was not waking up the device. I thought the battery was dead or that maybe I had a faulty connection. I troubleshooted without any success, only after disconnecting and reconnecting the battery, the device then turns on normally, and after timing-out (turning off), and pressing the button, the device wakes up normally.
I have now been using the device / testing my project for the past 2 weeks and have encountered this issue at least 6 times already (on Dongle), for no apparent reason, the press of the button will not wake up the device, and I'd have to open my project enclosure, disconnect and reconnect the battery to start using it again. This problem also happened twice on the DevKit.
I really have no idea how to troubleshoot this, since the device is in deep sleep mode if I understand correctly, although the GPIO module stays on... The only reason I can think of is that maybe I am missing some power management or gpio configuration. The weird thing is that 99% of the time, time-out/turn-off and wake-up button work fine. I did add these lines on the prj.conf file.
CONFIG_GPIO=y # Power Management Config CONFIG_PM=y CONFIG_PM_DEVICE=y
I would really like to try configuring the button using the hal/nrf_gpio library and using the cfg_sense_set() function, but, as mentioned, the same code properly compiles and works on the DevKit, I am able to also flash it on the Dongle but the button does not work. Am I missing something Dongle-specific in order to be able to use the system_off sample on it?
Thank you in advance.
Kind regards,
Alex Fernandez.