Fail to use gpiote edge triggering to wake the system up

I am now developing nRF52805 with SDK 17.1.0. I am trying to use long pressing to enter the sleeping mode and wake the system up using the short press. However, there is an issue that if I long-press the button, the system will enter the system off as expected, but instantly wake up operating like restarting. After I read the datasheet for nRF52, I realize that the wake-up should be triggered by the GPIO DETECT signal, however, if I would like to solve the above issue, I find that some developers use GPIOTE: GPIOTE_CONFIG_IN_SENSE_HITOLO function to sense the high-to-low signal of the gpio. But unfortunately, I try this function several times, but when I set the high accuracy as false, the function works the same as sense active low for the pin, while when I changed to set the high accuracy as true, the wake-up function could not work properly and stuck on the system off mode. Could anyone give me a way to solve these problems as I search the discussions but many of them meet the same issue but don't solve it? The following is my sample code. Thank you for the help.

#define BSP_BUTTON_0    20
#define BUTTON_0_ID     bsp_board_pin_to_button_idx(BSP_BUTTON_0)     // Define the button pin 20 ID

/**@brief Handler for shutdown preparation.
 */
bool shutdown_handler(nrf_pwr_mgmt_evt_t event)
{

    uint32_t err_code;

    switch (event)
    {
        // NRF_PWR_MGMT_SHUTDOWN_GOTO_SYSOFF = NRF_PWR_MGMT_EVT_PREPARE_WAKEUP
        // Once the NRF_PWR_MGMT_SHUTDOWN_GOTO_SYSOFF is achieved, the system will jump to NRF_PWR_MGMT_EVT_PREPARE_WAKEUP directly
        case NRF_PWR_MGMT_EVT_PREPARE_WAKEUP:

            NRF_LOG_INFO("The machine enters the SLEEP MODE!");
            
            
            NRF_LOG_INFO("To wake up the machine, please press the button!");

            nrf_drv_gpiote_in_uninit(BSP_BUTTON_0);           
	
            
            nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(false);
            

            in_config.pull = NRF_GPIO_PIN_PULLUP;                                           
            err_code = nrf_drv_gpiote_in_init(BSP_BUTTON_0, &in_config, NULL);           
            APP_ERROR_CHECK(err_code);
                                                                   
            nrf_drv_gpiote_in_event_enable(BSP_BUTTON_0, true);
            
            
            // Soft device system off function
            sd_power_system_off();
    
            break;
    }

    err_code = app_timer_stop_all();
    APP_ERROR_CHECK(err_code);

    return true;
}

static void short_button_press_cnt_timer_handler(void * p_content){}

/**@brief Register application shutdown handler with priority 0. */
NRF_PWR_MGMT_HANDLER_REGISTER(shutdown_handler, 0);


static void bsp_event_handler(bsp_event_t bsp_event)
{
    uint32_t err_code;

    switch (bsp_event)
    {   
        // BSP event for long press
        case BSP_EVENT_SLEEP:
            isLongPress = true; // Check the long pressing

            NRF_LOG_INFO("Long button press");
            NRF_LOG_INFO("The machine will enter SLEEP MODE in 1 second!");
            
            nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_GOTO_SYSOFF); //Enter the sleep mode
        break;
    }
}


void buttons_leds_init(bool * erase_bonds)
{
  // Initialize the BSP 
    uint32_t err_code = bsp_init(BSP_INIT_LEDS | BSP_INIT_BUTTONS, bsp_event_handler);
    APP_ERROR_CHECK(err_code);
    
    // Assign the Button RELEASE action to WAKEUP event
    err_code = bsp_event_to_button_action_assign(BUTTON_0_ID, BSP_BUTTON_ACTION_RELEASE, BSP_EVENT_WAKEUP);
    APP_ERROR_CHECK(err_code);
    
    // Assign the Button LONG PRESS action to SLEEP event
    err_code = bsp_event_to_button_action_assign(BUTTON_0_ID, BSP_BUTTON_ACTION_LONG_PUSH, BSP_EVENT_SLEEP);
    APP_ERROR_CHECK(err_code);

}

Parents
  • Hi,

    Have you checked the pin with a scope, to see if there is any bouncing signals from the button that can wake the chip too early? If you enter System OFF immediately when the long button press is detected, the chip may haven entered System OFF before you release the button. If there is then some bouncing signals on the pin when the long press is released, the chip may wake up from this.

    Configuring the GPIO with hi_accuracy will not work, as this will configure the pin using GPIOTE IN event, which is not active in System OFF mode. Setting hi_accuracy to false will use the GPIOTE PORT event, which will also configure the GPIO in sense mode. GPIO Sense mode is what is used to wakeup from System OFF.

    Best regards,
    Jørgen

  • Thank you for your reply Jorgen. To make the point more specific, my setting is that when I press the button for 3 seconds, the button_long_push event will be activated, and then, it will go to the system off mode. But in fact, for the general case, I could not exactly press the button for 3 seconds, it will often be longer than 3 seconds, say 3.1 seconds. Therefore, I guess that 3 seconds long press will make the system off and enable the wake-up button setting, and then a 0.1-second press will generate the DETECT signal and trigger the active-low sense, finally waking the system up. 

    If it is the issue, how could I avoid the system waking up before I release the button from the long pressing, and then only I  press the button again to wake the system up? Thank you for your help.

    Best regards,

    XIANGYU YU

Reply
  • Thank you for your reply Jorgen. To make the point more specific, my setting is that when I press the button for 3 seconds, the button_long_push event will be activated, and then, it will go to the system off mode. But in fact, for the general case, I could not exactly press the button for 3 seconds, it will often be longer than 3 seconds, say 3.1 seconds. Therefore, I guess that 3 seconds long press will make the system off and enable the wake-up button setting, and then a 0.1-second press will generate the DETECT signal and trigger the active-low sense, finally waking the system up. 

    If it is the issue, how could I avoid the system waking up before I release the button from the long pressing, and then only I  press the button again to wake the system up? Thank you for your help.

    Best regards,

    XIANGYU YU

Children
No Data
Related