This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

nRF52 wake up with GPIO from system off issue

Hi Sir/Miss,

I use nRF52832, softdevice 132 and SDK 17.1.0 to develop.

And, I want to use GPIO to wake up from system off.

We use external pull up resistor in wake up pin.

I try to set up the wake up pin as below:

uint32_t err_code;

nrf_gpio_cfg_input(BTN_START_SLEEP_PIN, NRF_GPIO_PIN_NOPULL);
nrf_gpio_pin_sense_t sense =  NRF_GPIO_PIN_SENSE_LOW;
nrf_gpio_cfg_sense_set(BTN_START_SLEEP_PIN, sense);

err_code = sd_power_system_off();
APP_ERROR_CHECK(err_code);

When I remove wake up pin configuration, it can enter sleep mode.

After I add it, system will enter sleep mode then wake up quickly. (It looks like woke up from sleep mode immediately)

How to set it?

Please help.

Thank you.

  • Hi,

    Can you try to change the code a bit, after configuring input by nrf_gpio_cfg_input(), then read the input pin until the input is high, before you enable sense nrf_gpio_cfg_sense_set().

    Best regards,
    Kenneth

  • Hi Kenneth,

    I change it as below:

        uint32_t err_code;
          
        nrf_gpio_cfg_input(BTN_START_SLEEP_PIN, NRF_GPIO_PIN_NOPULL);
        
        while(1)
        {
            if(nrf_gpio_pin_read(BTN_START_SLEEP_PIN) == 1)
            {
                nrf_gpio_pin_sense_t sense =  NRF_GPIO_PIN_SENSE_LOW;
                nrf_gpio_cfg_sense_set(BTN_START_SLEEP_PIN, sense);
                
                break;
            }
        }
        
        err_code = sd_power_system_off();
        APP_ERROR_CHECK(err_code);

    It works to me. Do you mean that it requires time to setup status?

     

    I encounter another problem in wake up.

    After system enters sleep mode, I want to wake it up.

    In my condition, to press button to wake up system which will turn on LED.

    At the first press button, LED turns on. But, it turns off quickly.

    I should press it second times, that will work normal.

    My process is pressing button, then to enter timer function is to do my application. Then, application will turn on LED.

    Furthermore, I try to replace my timer process function to turn on LED. That result is same.

    Here is my GPIO setting and trigger function in GPIO.

    nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
    in_config.pull = NRF_GPIO_PIN_NOPULL;
    
    err_code = nrf_drv_gpiote_in_init(BTN_START_SLEEP_PIN, &in_config, input_pin_handle);
    APP_ERROR_CHECK(err_code);
    
    nrf_drv_gpiote_in_event_enable(BTN_START_SLEEP_PIN, true);

    static void input_pin_handle(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
    {
        switch(pin)
        {
            case BTN_START_SLEEP_PIN:
                if(!dev_status.dev_enable)
                {
                    if(!dev_status.under_uninit)
                    {
                        if(dev_status.dev_mode == NORMAL || SLEEP)
                        {
                            dev_status.dev_enable = true;
                            
                            dev_gpio_low(LED1);
                        }
                    }
                    
                }
                else
                {
                    dev_status.dev_enable = false;
                    dev_status.dev_uninit = false;
                    
                    dev_gpio_high(LED1);
                    
                    app_user_status = APP_USER_UNINIT;
                    
                    shutdown_configuration();
                }
                break;
        }    
    }

    Thank you.

  • Countach said:
    It works to me. Do you mean that it requires time to setup status?

    It might be a very small delay from configuring input until it is settled, so yes, reading back the actual input level should solve this.

    Countach said:
    I encounter another problem in wake up.

    I don't have any suggestion here unfortunately here, I suggest to continue debugging, you can also on startup in main() check the reset reason, e.g. NRF_POWER->RESETREAS to find the startup reason if that might be helpful, remember to clear the register by writing '1' to bits to clear it.

    Best regards,
    Kenneth

  • Hi Kenneth,

    Sorry for reply late. I found out pressing button twice issue. That's my process problem. When I press button to wake up chip. It works and initialize peripheral components. Therefore, it must be pressed to enter running procedure again.

    Really appreciate your assistance.

Related