Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

why BLE_APP_UART example can use button 1 to button 4 to wakeup from sleep?

Hi Expert,

         why BLE_APP_UART example can use button 1 to button 4 to wakeup from sleep?

I checked source code I only saw the BTN_ID_WAKEUP  is 0.

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

I use the SDK nRF5_SDK_12.3.0_d7731ad

use the nRF52 DK and nRF51 DK.

Parents
  • Hello,

    I can see the same behavior that you do. The reason for this is that all the buttons and LEDs are initialized in buttons_leds_init() --> bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS, bsp_event_handler);

     

    If you disable the interrupts for these pins before enabling only the ones you want, it will only wake up on those button presses. 

    Your sleep_mode_enter() function should look something like this then:

    /**@brief Function for putting the chip into sleep mode.
     *
     * @note This function will not return.
     */
    static void sleep_mode_enter(void)
    {
        uint32_t err_code = bsp_indication_set(BSP_INDICATE_IDLE);
        APP_ERROR_CHECK(err_code);
    
        //disable old button interrupts
        nrf_drv_gpiote_in_event_disable(13);
        nrf_drv_gpiote_in_event_disable(14);
        nrf_drv_gpiote_in_event_disable(15);
        nrf_drv_gpiote_in_event_disable(16);
        // 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);
    }

     

    Best regards,

    Edvin

Reply
  • Hello,

    I can see the same behavior that you do. The reason for this is that all the buttons and LEDs are initialized in buttons_leds_init() --> bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS, bsp_event_handler);

     

    If you disable the interrupts for these pins before enabling only the ones you want, it will only wake up on those button presses. 

    Your sleep_mode_enter() function should look something like this then:

    /**@brief Function for putting the chip into sleep mode.
     *
     * @note This function will not return.
     */
    static void sleep_mode_enter(void)
    {
        uint32_t err_code = bsp_indication_set(BSP_INDICATE_IDLE);
        APP_ERROR_CHECK(err_code);
    
        //disable old button interrupts
        nrf_drv_gpiote_in_event_disable(13);
        nrf_drv_gpiote_in_event_disable(14);
        nrf_drv_gpiote_in_event_disable(15);
        nrf_drv_gpiote_in_event_disable(16);
        // 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);
    }

     

    Best regards,

    Edvin

Children
No Data
Related