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

Any simple method of setting sense input at 1st power cycle?

I'd like to use the pin sense function as the power switch of my NRF51822 device. That is to say, after the very first power cycle (reset or battery change), the device goes into power off mode directly and wait for button input. Clicking the button will toggle my device on/off.

I've considered using a power cycle counter. However, this requires RAM retention, which consumes power.

Is there any other way of setting sense input at the very first power cycle?

Thanks.

  • By switching off the power (either by switch or pulling battery), you will cause a Brownout reset. After a brownout reset, none of the registers will be retained, not even RESETREAS.

    You will not be able to configure the SENSE at the very first cycles as the chip will first execute the startup procedure (clear RAM etc), but you can do this in the top of your main.

    Try using the reset-value of RESETREAS (see chapter 11.2.1) to your advantage to check if it's a power-on-reset (ie: chip powered from 0 -> VDD).

    int main(void)
    {
        if ( (NRF_POWER->RESETREAS & RESETREAS_BITMASK) == 0)
        {
          /* set GPIO configuration and enable GPIOTE PORT event */
          /* Go to systemoff, wait for button press */
        }
        /* application continues here */
    }
    

    Cheers, Håkon

  • Thanks. I found NRF_POWER->RESETREAS is very useful. (1) Reset Pin Pressed, NRF_POWER->RESETREAS == 0x1; (2) Battery changed, NRF_POWER->RESETREAS == 0; (3) Wakeup from GPIO, NRF_POWER->RESETREAS == 0x1000; (4) Debug mode, NRF_POWER->RESETREAS == 0x100. And when you access this register, don't forget to clear it before next reset.

Related