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

nRF52832 Controlling Sleep Behavior with GPIO Pin

Hello,

I'm making an application that I want to have the following behavior:

1) 52832 starts in sleep mode

2)P0.14 pulls to LOW which brings out of sleep mode and then goes back to sleep after running application

3)P0.14 stays LOW and the 52832 stays in sleep mode

4)When P0.14 goes HIGH again 52832 comes back out of sleep mode and runs the application again

The problem I'm running into is that if P0.14 brings the 52832 out of sleep mode upon LOW that I can't keep the 52832 in sleep mode while that pin continues to stay LOW.  Is there a way to make the 52832 not come out of sleep mode after step 2 (above)?  For example:

1) 52832 starts in sleep mode

2)P0.14 pulls to LOW which brings out of sleep mode 

3) Somewhere in the application, change the logic to only wake up when P0.14 changes state/goes HIGH, and disable it from  coming out of state if LOW

4) 52832 then goes to sleep and only wakes up when P0.14 goes HIGH

5) After going HIGH and running the software configure to wake back up if P0.14 goes low

Thanks!

Parents
  • Hi,

    Which sleep mode are you using (System ON/System OFF)?

    How have you configured the GPIO for wakeup from sleep mode? It should definitely be possible to change the configuration after wakeup, to only wakeup on next transition to high. How to achieve this depends on how you have configured the GPIO in the first place, so we would need to see your code in order to help you.

    Best regards,
    Jørgen

Reply
  • Hi,

    Which sleep mode are you using (System ON/System OFF)?

    How have you configured the GPIO for wakeup from sleep mode? It should definitely be possible to change the configuration after wakeup, to only wakeup on next transition to high. How to achieve this depends on how you have configured the GPIO in the first place, so we would need to see your code in order to help you.

    Best regards,
    Jørgen

Children
  • I had just been using the function provided in the BLE_app example which is:

    static void sleep_mode_enter(void)
    {
        uint32_t 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);
    }

    So this is just putting the device in System ON mode it looks like?  

    Then to use the switch I just configured the pin as below and read its state directly.  

    //Button is P0.14
    nrf_gpio_cfg_input(Button, NRF_GPIO_PIN_PULLUP);
    

    So it looks like I need to change to put the device into System OFF mode, then make the condition to come out of System OFF mode to be when P0.14 goes HIGH as it will stay LOW until the system needs to wake up again.

    Is this the correct way to go about this?  And how do I configure to only come out of System OFF mode upon the single P0.14 HIGH condition?

  • The sleep_mode_enter() function will put the system in System OFF mode, as you can see it calls sd_power_system_off(). The function bsp_btn_ble_sleep_mode_prepare() will also configure default button for wakeup (BTN_ID_WAKEUP/"Button 1"). 

    nrf_gpio_cfg_input() will not configure the GPIO for wakeup from System OFF mode, only as a normal input. This requires the pin to be configured in SENSE mode, which is configured using nrf_gpio_cfg_sense_input(). Note that the BSP library, if included/used in your project, may configure the pins used as by LEDs and Buttons on the DK already.

  • Thanks, this worked and I was able to get the behavior I wanted using the nrf_gpio_cfg_sense_input() as follows!

    nrf_gpio_cfg_sense_input(Button, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_HIGH);

    The issue was that I used button 1 which is included in the function bsp_wakeup_button_enable().  Even though I configured the button later with nrf_gpio_cfg_input() the bsp_wakeup_button_enable() was bringing the device out of sleep mode, so I had to remove this as well.  I did this by making a separate sleep_mode_enter() function, one with the bsp_wakeup_button_enable() and the other with it disabled (for the condition of going into sleep mode in sense mode).  I'm not posting the full code/logic because I think it would just be more complicated but if anyone wants to see it message me and I can add it in.

Related