nrf52840 cannot wake up from sleep mode.

Hi friend,

I am using SDK16.0, and the version of softdevice is S140 V7.0.1. The MCU can enter sleep mode. But it cannot wake up after entering sleep mode. My code is as follows. What is wrong with my code? Can someone help me?

Thank you very much.

Ted Wu. 

At bsp_btn_ble.c
#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. */

At pca10056.h
#define BSP_BUTTON_TRIGGER   NRF_GPIO_PIN_MAP(1,1)
#define BSP_BUTTON_POWER     NRF_GPIO_PIN_MAP(1,10)
#define BSP_BUTTON_USB       NRF_GPIO_PIN_MAP(1,14)
#define BSP_BUTTON_DOWN      NRF_GPIO_PIN_MAP(1,11)
#define BSP_BUTTON_UP        NRF_GPIO_PIN_MAP(1,3)
#define BSP_BUTTON_LEFT      NRF_GPIO_PIN_MAP(0,10)
#define BSP_BUTTON_RIGHT     NRF_GPIO_PIN_MAP(1,4)
#define BSP_BUTTON_CANCEL    NRF_GPIO_PIN_MAP(1,2)
#define BSP_BUTTON_ENTER     NRF_GPIO_PIN_MAP(0,9)

#define BUTTONS_LIST { BSP_BUTTON_TRIGGER,  \
                       BSP_BUTTON_POWER, BSP_BUTTON_USB,\
                       BSP_BUTTON_DOWN, BSP_BUTTON_UP, \
                       BSP_BUTTON_LEFT,BSP_BUTTON_RIGHT, \
                       BSP_BUTTON_CANCEL,BSP_BUTTON_ENTER }

At bsp.c
static const app_button_cfg_t app_buttons[BUTTONS_NUMBER] =
{
    {BSP_BUTTON_TRIGGER, APP_BUTTON_ACTIVE_LOW, BUTTON_PULL, bsp_button_event_handler },
    {BSP_BUTTON_POWER, APP_BUTTON_ACTIVE_HIGH, BUTTON_NOPULL, bsp_button_event_handler },
    {BSP_BUTTON_USB,    APP_BUTTON_ACTIVE_LOW, BUTTON_PULL, bsp_button_event_handler },
    {BSP_BUTTON_DOWN,   APP_BUTTON_ACTIVE_LOW, BUTTON_PULL, bsp_button_event_handler },
    {BSP_BUTTON_UP,     APP_BUTTON_ACTIVE_LOW, BUTTON_PULL, bsp_button_event_handler },
    {BSP_BUTTON_LEFT,   APP_BUTTON_ACTIVE_LOW, BUTTON_PULL, bsp_button_event_handler },
    {BSP_BUTTON_RIGHT,  APP_BUTTON_ACTIVE_LOW, BUTTON_PULL, bsp_button_event_handler },
    {BSP_BUTTON_CANCEL, APP_BUTTON_ACTIVE_LOW, BUTTON_PULL, bsp_button_event_handler },
    {BSP_BUTTON_ENTER,  APP_BUTTON_ACTIVE_LOW, BUTTON_PULL, bsp_button_event_handler },
    ...
}

At main.c
#define BTN_TRIGGER_PIN           0
#define BTN_POWER_PIN             1
#define BTN_USB_PIN               2
#define BTN_DOWN_PIN              3
#define BTN_UP_PIN                4
#define BTN_LEFT_PIN              5
#define BTN_RIGHT_PIN             6
#define BTN_CANCEL_PIN            7
#define BTN_ENTER_PIN             8

static void buttons_leds_init(bool * p_erase_bonds)
{
    ...
	UNUSED_RETURN_VALUE(bsp_event_to_button_action_assign(BTN_TRIGGER_PIN,
                                                          BSP_BUTTON_ACTION_RELEASE,
                                                          (bsp_event_t)CONCAT_2(BSP_USER_EVENT_RELEASE_, BTN_TRIGGER_PIN)));	
	UNUSED_RETURN_VALUE(bsp_event_to_button_action_assign(BTN_POWER_PIN,
                                                         BSP_BUTTON_ACTION_RELEASE,
                                                         (bsp_event_t)CONCAT_2(BSP_USER_EVENT_RELEASE_, BTN_POWER_PIN)));	

	UNUSED_RETURN_VALUE(bsp_event_to_button_action_assign(BTN_POWER_PIN,
                                                          BSP_BUTTON_ACTION_LONG_PUSH,
                                                          (bsp_event_t)CONCAT_2(BSP_USER_EVENT_LONG_, BTN_POWER_PIN)));		
	UNUSED_RETURN_VALUE(bsp_event_to_button_action_assign(BTN_USB_PIN,
                                                         BSP_BUTTON_ACTION_RELEASE,
                                                         (bsp_event_t)CONCAT_2(BSP_USER_EVENT_RELEASE_, BTN_USB_PIN)));	
	UNUSED_RETURN_VALUE(bsp_event_to_button_action_assign(BTN_DOWN_PIN,
                                                          BSP_BUTTON_ACTION_RELEASE,
                                                          (bsp_event_t)CONCAT_2(BSP_USER_EVENT_RELEASE_, BTN_DOWN_PIN)));	
	UNUSED_RETURN_VALUE(bsp_event_to_button_action_assign(BTN_UP_PIN,
                                                          BSP_BUTTON_ACTION_RELEASE,
                                                          (bsp_event_t)CONCAT_2(BSP_USER_EVENT_RELEASE_, BTN_UP_PIN)));	
	UNUSED_RETURN_VALUE(bsp_event_to_button_action_assign(BTN_LEFT_PIN,
                                                          BSP_BUTTON_ACTION_RELEASE,
                                                          (bsp_event_t)CONCAT_2(BSP_USER_EVENT_RELEASE_, BTN_LEFT_PIN)));												
	UNUSED_RETURN_VALUE(bsp_event_to_button_action_assign(BTN_RIGHT_PIN,
                                                          BSP_BUTTON_ACTION_RELEASE,
                                                          (bsp_event_t)CONCAT_2(BSP_USER_EVENT_RELEASE_, BTN_RIGHT_PIN)));	
	UNUSED_RETURN_VALUE(bsp_event_to_button_action_assign(BTN_CANCEL_PIN,
                                                          BSP_BUTTON_ACTION_RELEASE,
                                                          (bsp_event_t)CONCAT_2(BSP_USER_EVENT_RELEASE_, BTN_CANCEL_PIN)));
	UNUSED_RETURN_VALUE(bsp_event_to_button_action_assign(BTN_ENTER_PIN,
                                                          BSP_BUTTON_ACTION_RELEASE,
                                                          (bsp_event_t)CONCAT_2(BSP_USER_EVENT_RELEASE_, BTN_ENTER_PIN)));
    UNUSED_RETURN_VALUE(bsp_event_to_button_action_assign(BTN_DOWN_PIN,
                                                          BSP_BUTTON_ACTION_LONG_PUSH,
                                                          (bsp_event_t)CONCAT_2(BSP_USER_EVENT_LONG_, BTN_DOWN_PIN)));		
	UNUSED_RETURN_VALUE(bsp_event_to_button_action_assign(BTN_UP_PIN,
                                                          BSP_BUTTON_ACTION_LONG_PUSH,
                                                          (bsp_event_t)CONCAT_2(BSP_USER_EVENT_LONG_, BTN_UP_PIN)));
}

static void sleep_mode_enter(void)
{
    ret_code_t err_code;

    NRF_LOG_INFO("%s", __FUNCTION__);
    err_code = bsp_indication_set(BSP_INDICATE_IDLE);
    APP_ERROR_CHECK(err_code);

    // Prepare wakeup buttons.
//    nrf_gpio_cfg_sense_input(BSP_BUTTON_TRIGGER, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
    nrf_gpio_cfg_sense_input(0, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
    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);
}

static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
{
    ret_code_t err_code;
	
    switch (ble_adv_evt)
    {
        case BLE_ADV_EVT_FAST:
            break;
        case BLE_ADV_EVT_IDLE:
            sleep_mode_enter();
            break;
        case BLE_ADV_EVT_WHITELIST_REQUEST:
            ...
            break;
        default:
            // No implementation needed.
            break;
    }
}

Parents Reply Children
No Data
Related