I tested the code below to make the board go to sleep and wake up on each button press. When I start, it draws 30ua, but when I press the button it shoots up to 200ua (a clear sign that it is awake) and it stays on. It does not seem to sleep drawing current even though I am asking it on the code.
I have tried this with ALL last 5 SDks and the results are exactly the same. I am using DK PCA10056 1.1.0 2019.19 683309915. I tried 2 different boards with the same results. I am using the power profiler software and board to measure current (jumper off, set to DK, etc). My current profiler board is PCA63511 1.1.0 4EB01DE5. I am using the button on the board.
See pictures below. How can I make the chip sleep after first button press so less current is drawn?
#include <stdbool.h>
#include "nrf.h"
#include "nrf_drv_gpiote.h"
#include "app_error.h"
#include "boards.h"
#include "nrf_delay.h"
#ifdef BSP_BUTTON_0
#define PIN_IN BSP_BUTTON_0
#endif
#ifndef PIN_IN
#error "Please indicate input pin"
#endif
#ifdef BSP_LED_0
#define PIN_OUT BSP_LED_0
#endif
#ifndef PIN_OUT
#error "Please indicate output pin"
#endif
int buttonPressed = 0;
int buttonReleased = 0;
void in_pin_handlerlow(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
ret_code_t err_code;
if(pin == PIN_IN)
{
if(buttonPressed==0) {
buttonPressed = 1;
buttonReleased = 0;
} else {
if(buttonReleased == 0) {
buttonReleased = 1;
buttonPressed = 0;
}
}
//Turn off LED to indicate the nRF5x is in System-off mode
nrf_drv_gpiote_out_toggle(PIN_OUT);
NRF_POWER->SYSTEMOFF = 1;
}
}
/**
* @brief Function for configuring: PIN_IN pin for input, PIN_OUT pin for output,
* and configures GPIOTE to give an interrupt on pin change.
*/
static void gpio_init(void)
{
ret_code_t err_code;
err_code = nrf_drv_gpiote_init();
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_out_config_t out_config = GPIOTE_CONFIG_OUT_SIMPLE(false);
err_code = nrf_drv_gpiote_out_init(PIN_OUT, &out_config);
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_out_clear(PIN_OUT);
nrf_drv_gpiote_in_config_t in_configlow = NRFX_GPIOTE_CONFIG_IN_SENSE_TOGGLE(false);
in_configlow.pull = NRF_GPIO_PIN_PULLUP;
err_code = nrf_drv_gpiote_in_init(PIN_IN, &in_configlow, in_pin_handlerlow);
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_in_event_enable(PIN_IN, true);
}
/**
* @brief Function for application main entry.
*/
int main(void)
{
gpio_init();
while (true)
{
// Do nothing.
__WFE();
__SEV();
__WFE();
}
}
See below for output from Power profiler before and after button press

