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

Wake up from sleep mode

Hello,

       I want to use ble_app_uart example. I'm usign nRF52832 with nRF5_SDK v15. I need to put the MCU in sleep mode. I can do that. When the MCU awakes from sleep, I do not want to run the BLE stack directly. I will make some measurements and then if it is needed, I will run the BLE stack. 

      How can I do this ? any idea ?

Best Regards 

  • Hi

    Thanks for the code. 

    It confirms that your code will get stuck if you leave the else {} clause, since you are left in the for(;;) loop forever without ever entering system OFF again. The only way to return to the top of main then is to perform a power or pin reset. 

    Best regards
    Torbjørn

  • Not directly answering your question, but be aware that sometimes RESETREAS is not what you might expect. An example is if you are using the reset pin and the device is programmed while debugging with an erase-program cycle. The SystemInit() function in particular can issue a soft reset which can affect RESETREAS and puzzled me for a while, particularly as I was also switch NFC pins toGPIO which issued effectively two extra reset (NFC pins then Reset pin)

        /* Configure GPIO pads as pPin Reset pin if Pin Reset capabilities desired. If CONFIG_GPIO_AS_PINRESET is not
          defined, pin reset will not be available. One GPIO (see Product Specification to see which one) will then be
          reserved for PinReset and not available as normal GPIO. */
        #if defined (CONFIG_GPIO_AS_PINRESET)
            if (((NRF_UICR->PSELRESET[0] & UICR_PSELRESET_CONNECT_Msk) != (UICR_PSELRESET_CONNECT_Connected << UICR_PSELRESET_CONNECT_Pos)) ||
                ((NRF_UICR->PSELRESET[1] & UICR_PSELRESET_CONNECT_Msk) != (UICR_PSELRESET_CONNECT_Connected << UICR_PSELRESET_CONNECT_Pos))){
                NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos; // Write Enable
                while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
                NRF_UICR->PSELRESET[0] = 21;
                while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
                NRF_UICR->PSELRESET[1] = 21;
                while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
                NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos; // Read-only Enable
                while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
                // UICR changes require a reset to be effective
                NVIC_SystemReset();
            }
        #endif
    

  • With RESETREAS it is always better to do a bit pattern compare with an AND.  Resetreas accumulates flags until a power cycle.  You could inadvertently have a spare flag set that would cause your equal statement to fail.

  • Nothing has changed even if I put sleep_mode_enter(); in the else condition.

  • So are you saying that the only difference between the working and non working code is the following line at line 8 of your example?

    NRF_POWER->RESETREAS = 0xffffffff;

Related