This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
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

How do you put the nrf51822 chip to sleep?

I am wondering how you put the nrf51822 chip to sleep. I've determined that the way to do this with the soft device is sd_app_event_wait() in the while loop. What about non-softdevice?

I am wanting to have it sleep until woken by interrupts, then sleep again. In another example, I found __wfi() used. Also, __WFI(). Neither seem to do anything, though.

Thanks!

Parents
  • Something like this should work:

    
    void sleep()
    {
    
        /* Clear Event Register */
        __SEV();
        /* Wait for event */
        __WFE();
        /* Wait for event */
        __WFE();
    }
    
    
  • This is not the solution for every situation and please do not copy it without understanding. Clearing event flag just before the WFE that should actually wait for event basically doest the same what WFI instruction. WFI instruction is not safe because it would not wake up the system when interrupt happens just before its call. You may call WFE(); SEV(); WFE(); processing(); Now you are sure that you clear event flag that was set in any interrupts just before processing all the events in the main loop. Single WFE should also clear the flag but it may be set again if there would be many interrupts processing just after system wake-up.

    If you do not clear the event flag your main loop may be processed more times you expect. Just thing twice before you clear event flag: in worst case you may lost information about event that should be processed.

Reply
  • This is not the solution for every situation and please do not copy it without understanding. Clearing event flag just before the WFE that should actually wait for event basically doest the same what WFI instruction. WFI instruction is not safe because it would not wake up the system when interrupt happens just before its call. You may call WFE(); SEV(); WFE(); processing(); Now you are sure that you clear event flag that was set in any interrupts just before processing all the events in the main loop. Single WFE should also clear the flag but it may be set again if there would be many interrupts processing just after system wake-up.

    If you do not clear the event flag your main loop may be processed more times you expect. Just thing twice before you clear event flag: in worst case you may lost information about event that should be processed.

Children
No Data
Related