always automatic wakeup after entering SYSTEM OFF mode

Hi everyone,

I wanna implement the wakeup from SYSTEM OFF by button. The project is based on the ble_app_uart example. After receiving a command from BLE, nrf will go to SYSTEM OFF , the code is here: 

 case 29:  // SYSTEM OFF mode
                                  nrf_delay_ms(500);
                                  sprintf(bletext,"SYSTEM OFF......\r\n"); BLE_TEXT(bletext);
                                  sprintf(bletext,"SYSTEM OFF......\r\n"); BLE_TEXT(bletext);
                                  sprintf(bletext,"SYSTEM OFF......\r\n"); BLE_TEXT(bletext);
                                  nrf_delay_ms(500);
                                  err_code = bsp_wakeup_button_enable(BUTTON_5);
                                  APP_ERROR_CHECK(err_code);
                                 
                                  nrf_delay_ms(500);
                                  /*err_code = sd_power_system_off();
                                  APP_ERROR_CHECK(err_code);*/
                                  NRF_POWER->SYSTEMOFF = 1;

Every time it goes to OFF mode, it will automatically restart booting after about 1-2 seconds

I used the sd_power_reset_reason_get() and it shows that it's reset from soft reset detected (SREQ)

I read several post about this topic and it looks like sd_power_system_off() doesn't work in debugging mode. I don't know how to check if I'm in debug mode or not, so I used both sd_power_system_off() and NRF_POWER->SYSTEMOFF = 1, same problem, no difference. And I tried both connect our pcb to the nRF52DK and pcb runs separately communicating with nRF52DK through BLE, same problem.

Can anyone help with this? Thanks in advance

Parents
  • The system will stay in OFF mode if I comment out 

    err_code = bsp_wakeup_button_enable(BUTTON_5);
    APP_ERROR_CHECK(err_code);

    We use a custom PCB and there's no bsp_buttons on it, but we have a button connected to P0.24, and I added it in pca10040.h and sdk_config.h as following:

    // in pca10040.h
    #define BUTTONS_NUMBER 5   //4------>5
    #define BUTTON_5  NRF_GPIO_PIN_MAP(0,24)
    #define BUTTONS_LIST { BUTTON_1, BUTTON_2, BUTTON_3, BUTTON_4, BUTTON_5 }
    
    // in sdk_config.h
    #define GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS 5   //4--->5
    
    And in main bsp_event_handler, we do enter the case BSP_EVENT_KEY_4 when the button is pressed, so I guess it should work the same as those buttons on the DK. But after I set that button for wakeup as "bsp_wakeup_button_enable(BUTTON_5);", it will automatically wakeup without being pressed, what might be wrong?

  • Which pin does BUTTON_5 map to in your code? And how is this pin connected on your HW? When you configure that as an input and as a wakeup source, a change on the state of that pin can wake up the device. If that is controlled by something else and/or is floating, you will not have any control over what happens. Generally it is essential to have control over your inputs and to ensure that you hever have floating digital inputs.

Reply
  • Which pin does BUTTON_5 map to in your code? And how is this pin connected on your HW? When you configure that as an input and as a wakeup source, a change on the state of that pin can wake up the device. If that is controlled by something else and/or is floating, you will not have any control over what happens. Generally it is essential to have control over your inputs and to ensure that you hever have floating digital inputs.

Children
  • It's connected to PIN29 (p0.24) using #define BUTTON_5  NRF_GPIO_PIN_MAP(0,24). On HW it connects PIN29 and GND (already pullup in bsp.c, and active_state = 0)

    I have a bsp event for that button and I only enter that event when I press the button, is that enough to prove that it's not floating

    Thanks for your help

  • Hi,

    Is it so that pin 29 is connected to ground when pushed, and that you do not have a pull-up? If so it will be floating when the button is not pressed, so yes, you need a pull-up. Note that there are internal pull resistors for every GPIO, so there is no need for an external pull-up - just enable the internal pull-up. 

  • It's already pullup in bsp.c when I #define BSP_BUTTON_4   BUTTON_5

    And during the 4-5 seconds before it automatic wakeup, the button doesn't work(won't wakeup the chip on press) and after the wakeup, pressing the button will enter the bsp_event

    Following is all the code about this button

    // in pca10040.h
    #define BUTTONS_NUMBER 5   //4------>5
    #define BUTTON_5  NRF_GPIO_PIN_MAP(0,24)
    #define BUTTONS_LIST { BUTTON_1, BUTTON_2, BUTTON_3, BUTTON_4, BUTTON_5 }
    #define BSP_BUTTON_4   BUTTON_5
    
    // in sdk_config.h
    #define GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS 5   //4--->5
    
    // in bsp.c
    #ifdef BSP_BUTTON_4
        {BSP_BUTTON_4, false, BUTTON_PULL, bsp_button_event_handler},
        #endif
        
    // in main.c
    // in bsp_event_handler
    case BSP_EVENT_KEY_4:  //BUTTON_5
                sprintf(bletext,"button_pcb detected\r\n");BLE_TEXT(bletext);
                break;
    // in ble_nus_event_handler
    case 29:  // SYSTEM OFF mode
                nrf_delay_ms(500);
                sprintf(bletext,"SYSTEM OFF......\r\n"); BLE_TEXT(bletext);
                sprintf(bletext,"SYSTEM OFF......\r\n"); BLE_TEXT(bletext);
                sprintf(bletext,"SYSTEM OFF......\r\n"); BLE_TEXT(bletext);
                nrf_delay_ms(500);
    
                err_code = bsp_wakeup_button_enable(BUTTON_5);
                APP_ERROR_CHECK(err_code);
                                     
                nrf_delay_ms(500);
                /*err_code = sd_power_system_off();
                APP_ERROR_CHECK(err_code);*/
                NRF_POWER->SYSTEMOFF = 1;

  • Hi,

    I don't see anything obviously wrong here. Just to sum up:

    • The device always wakes up after 4-5 seconds in system off, but only if you have called bsp_wakeup_button_enable(BUTTON_5); before entering system OFF.
    • And you cannot wake up before this from system of by pressing the button.
    • If wakeup button was not configured, device stays in system off forever.

    Is that correct?

    I noticed another thing from one of your earlier posts. There you wrote that "RESETREAS register always shows reset by soft reset". That is not expected. You should see that it had woken up from system-off mode. Could it be that you are not testing system off mode, but rather emulated system off? Do you have a debugger attached when doing this test? I ask because system off does not work while debugging.

    Other questions: have you tested that this button works as expected when not using it to wake up from system off mode, so that the HW is good? Do you have a WDT running? If yes, have you tested without it?

  • The sum up is right.

    The custom pcb runs separately and the DK is used to receive the BLE data and show it on DC serial port, is that considered as debugging mode? And I tried both sd_power_system_off() and NRF_POWER->SYSTEMOFF = 1, I guess it's not emulated off? I'm not sure about WDT, if it's not set by default, I have no code for that.

    As I mentioned below, if I use

    void configure_gpio_wakeup(uint32_t pin_number, nrf_gpio_pin_sense_t sense)
    
    {
    
    nrf_gpio_pin_latch_clear(pin_number);
    
    nrf_gpio_cfg_watcher(pin_number);
    
    nrf_gpio_cfg_sense_set(pin_number, sense);
    
    }
    
    configure_gpio_wakeup(BUTTON_5, NRF_GPIO_PIN_SENSE_LOW);
    everything is fine, no auto reset and wake up on button, RESETREAS shows wakeup on GPIO DETECT

Related