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

For nRF52832 SDK 17.0.2 ,How to enter Sleep Mode (Power Off Mode) (Suspend Mode) then press the Button1 for wake up ??

For nRF52832 SDK 17.0.2 ,How to enter Sleep Mode (Power Off Mode) (Suspend Mode) then press the Button1 for wake up ??

  • Now I use following sleep_mode_enter() will be reset immediately ,can not enter sleep mode to wait button1 for wake up.

    static void sleep_mode_enter(void)
    {

     ret_code_t err_code;
    nrf_drv_twi_uninit(&m_twi); //keli

    nrf_gpio_cfg_sense_input(BUTTON1_GPIO_PIN,NRF_GPIO_PIN_PULLUP,NRF_GPIO_PIN_SENSE_LOW);
    //nrf_gpio_cfg_sense_input(BUTTON2_GPIO_PIN,NRF_GPIO_PIN_PULLUP,NRF_GPIO_PIN_SENSE_LOW);
    //nrf_gpio_cfg_sense_input(BUTTON3_GPIO_PIN,NRF_GPIO_PIN_PULLUP,NRF_GPIO_PIN_SENSE_LOW);
    //nrf_gpio_cfg_sense_input(BUTTON4_GPIO_PIN,NRF_GPIO_PIN_PULLUP,NRF_GPIO_PIN_SENSE_LOW);

    NVIC_DisableIRQ(GPIOTE_IRQn);
    NVIC_ClearPendingIRQ(GPIOTE_IRQn);

    err_code = bsp_indication_set(BSP_INDICATE_IDLE);
    APP_ERROR_CHECK(err_code);

    // Prepare wakeup buttons.
    err_code = bsp_btn_ble_sleep_mode_prepare();
    APP_ERROR_CHECK(err_code);

    // Go to system-off mode (this function will not return; wakeup will cause a reset).
    err_code = sd_power_system_off();
    APP_ERROR_CHECK(err_code);

    }

  • Hi,

    Both nrf_gpio_cfg_sense_input and bsp_btn_ble_sleep_mode_prepare should work if configured correctly.

    What have you defined BTN_ID_WAKEUP and BTN_ID_WAKEUP_BOND_DELETE to? Are these pins connected to buttons, and are the pins in the correct state? If any of the pins configured as wakeup pins are pulled in the wrong state or left floating, an immediate reset would be expected.

    uint32_t bsp_btn_ble_sleep_mode_prepare(void)
    {
        uint32_t err_code;
    
        err_code = bsp_wakeup_button_enable(BTN_ID_WAKEUP);
        RETURN_ON_ERROR_NOT_NOT_SUPPORTED(err_code);
    
        err_code = bsp_wakeup_button_enable(BTN_ID_WAKEUP_BOND_DELETE);
        RETURN_ON_ERROR_NOT_NOT_SUPPORTED(err_code);
    
        return NRF_SUCCESS;
    }

    By default, these are defined to 0 and 1, and will use the BUTTON_0/BUTTON_1 configs from your board header file (pca10040.h, etc.).

    Best regards,
    Jørgen

  • uint32_t bsp_btn_ble_sleep_mode_prepare(void)
    {
    uint32_t err_code;

    err_code = bsp_wakeup_button_enable(BTN_ID_WAKEUP);
    RETURN_ON_ERROR_NOT_NOT_SUPPORTED(err_code);

    err_code = bsp_wakeup_button_enable(BTN_ID_WAKEUP_BOND_DELETE);
    RETURN_ON_ERROR_NOT_NOT_SUPPORTED(err_code);

    return NRF_SUCCESS;
    }

    ----------------------------------------------------------------------------------------------------------------

    #define BTN_ID_WAKEUP 0 /**< ID of button used to wake up the application. */
    #define BTN_ID_SLEEP 0 /**< ID of button used to put the application into sleep mode. */
    #define BTN_ID_DISCONNECT 0 /**< ID of button used to gracefully terminate a connection on long press. */
    #define BTN_ID_WAKEUP_BOND_DELETE 1 /**< ID of button used to wake up the application and delete all bonding information. */
    #define BTN_ID_WHITELIST_OFF 1 /**< ID of button used to turn off usage of the whitelist. */

  • #define BTN_ID_WAKEUP 0 /**< ID of button used to wake up the application. */

    #define BTN_ID_WAKEUP_BOND_DELETE 1 /**< ID of button used to wake up the application and delete all bonding information. */

    I have checked the pins in the correct state(Button1),But it still be reset  immediately. Why ?

  • If the chip is waken from System OFF, it is most likely an issue with the GPIO configurations.

    Can you check the RESETREAS register after reset, to make sure that the chip was reset by wake from System OFF/GPIO?

    The APP_ERROR_CHECK() could also cause a reset, in case you are in debug mode, as this will cause the chip to enter "Emulated System OFF":

    // Go to system-off mode (this function will not return; wakeup will cause a reset).
    err_code = sd_power_system_off();
    APP_ERROR_CHECK(err_code);

Related