GPIO wakeup from System ON sleep

Hi,

I'm currenty try to code GPIO wakeup from System ON sleep with system_on_wakeup_on_gpio as a reference.

My circuit is powerd by solar panel via control board. In this design P0_04 on nRF52832 receives the PWR_GOOD signal.

I would like to keep it in low power mode until the PWR_GOOD flag is set at the beginning of the main function.

The following code does not work even if VCC is applied manually to P0_04.

// Standards
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <math.h>

// nRF
#include "nrf.h"
#include "app_error.h"
#include "app_timer.h"
#include "app_scheduler.h"
#include "nrf_delay.h"
#include "nrf_drv_clock.h"
#include "nrf_pwr_mgmt.h"
#include "nrf_gpio.h"
#include "nrf_drv_twi.h"

// User defined pin configuration
#define PIN_PWR_GOOD 4

int main(void)
{
  nrf_gpio_cfg_sense_input(PIN_PWR_GOOD, NRF_GPIO_PIN_PULLDOWN, NRF_GPIO_PIN_SENSE_HIGH);
  
  // Enter System ON sleep mode
  __WFE();
  __SEV();
  __WFE();
  
  ...
  
}

I removed the unnecessary lines from the sample code above, is that the problem? I do not know how the program counter behaves after it is taken out of sleep mode.

Currently I am using the following statement and would like to consider saving electricity during this waiting period.

nrf_gpio_cfg_input(4, NRF_GPIO_PIN_PULLDOWN);
while (nrf_gpio_pin_read(4) == false);

tyro

Parents
  • Hi,

    To wake-up from System ON mode (entered when you call __WFE) you need to configure the pin to trigger an interrupt. Here you have only configured the pin with sense enabled without configuration the GPIOTE interrupt. You can however use this configuration to wake the chip from  System OFF mode. If this is what you want, then you can replace   __WFE();__SEV();__WFE(); with NRF_POWER->SYSTEMOFF=1.

    Best regards,

    Vidar

  • Hi Vidar,

    I found a way to use System OFF sleep, which consumes less power than System ON sleep, so I decided to use your suggestion.

    #define PIN_PWR_GOOD 4
    
    void PWR_GOOD_wait_sysOFF(void)
    {
        nrf_gpio_cfg_sense_input(PIN_PWR_GOOD, NRF_GPIO_PIN_PULLDOWN, NRF_GPIO_PIN_SENSE_HIGH);
    
        // Enter system OFF. After wakeup the chip will be reset, and code execution will run from the top 
        NRF_POWER->SYSTEMOFF = 1;
        
        for(;;){}
    }
    
    int main(void)
    {
        nrf_gpio_cfg_input(PIN_PWR_GOOD, NRF_GPIO_PIN_PULLDOWN);
        
        if (nrf_gpio_pin_read(PIN_PWR_GOOD) == 0)
        {
            PWR_GOOD_wait_sysOFF();
        }
        ...
    }

    Thank you for your advice.

    tyro

Reply
  • Hi Vidar,

    I found a way to use System OFF sleep, which consumes less power than System ON sleep, so I decided to use your suggestion.

    #define PIN_PWR_GOOD 4
    
    void PWR_GOOD_wait_sysOFF(void)
    {
        nrf_gpio_cfg_sense_input(PIN_PWR_GOOD, NRF_GPIO_PIN_PULLDOWN, NRF_GPIO_PIN_SENSE_HIGH);
    
        // Enter system OFF. After wakeup the chip will be reset, and code execution will run from the top 
        NRF_POWER->SYSTEMOFF = 1;
        
        for(;;){}
    }
    
    int main(void)
    {
        nrf_gpio_cfg_input(PIN_PWR_GOOD, NRF_GPIO_PIN_PULLDOWN);
        
        if (nrf_gpio_pin_read(PIN_PWR_GOOD) == 0)
        {
            PWR_GOOD_wait_sysOFF();
        }
        ...
    }

    Thank you for your advice.

    tyro

Children
No Data
Related