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);

}

Related