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

Sleep until WDT timesout

Hi All,

I have up to 8 nRF52832 devices sending data back to a base unit (another nRF52832 device.)   What I'm trying to do is have the remote units wakeup at a given time,

read sensors and send message back to the base unit.  (Each remote has a unique ID that the base unit tracks the data by.)

Currently I'm using a watchdog timer to bring the device out of sleep mode (reboot and read nvram to reload system state.)

I've been trying to use:

while(1)

{

__WFE();

}

To put the device asleep, but I'm thinking the devices are waking each other up.  (I'm getting more updates than expected and battery life is lower than expected.)

Is there a better way to get the unit to stay asleep?

thanks,

Bob

  • Hello, 

    First thing I'd check is if the external sensors are in low-power mode during sleep, if some sensor stays in measuring mode it can drain your battery regardless of what your device does. 

    Second, I'd use `nrf_pwr_mgmt_run();` instead of direct call to `__WFE();` 

    Third, nRF52 can spend relatively long time in active mode during boot, I'd rather use timer interrupt to wake up from sleep and let watchdog handle only the cases where program has hanged. 

  • Hi Otso,

    Thanks for the response,  we have mosfets that turn on/off the sensors so I'm not thinking the problem is sensors draining batteries.

    Can you point to an example using nrf_pwr_mgmt_run()  with timer triggering it?

    thanks again!
    Bob

  • Ok, so I'm working on adding nrf_pwr_mgmt_run() to my project, which obviously needs nrf_pwr_mgmt.h, when I start compiling it starts complaining about wanting nrf_section_iter.... so I add that.  The latest complain is it wants __start_pwr_mgmt_data and __stop_pwr_mgmt_data defined.   (Digging into that I find I need sections_placement.xml file updated, but I only see flash_placement.xml file.)

    So before I tunnel down this rabbit hole any further.  Is there a simple example that just puts the device in the lowest power mode (with some internal timer or WDT that will bring it out of sleep mode after a set period.  External input is not an option.)

    Thanks much!
    Bob

    FYI my current setup puts the device in sleep mode drawing 210uAmps  (When the device is awake it draws about 8mAmps.)

  • Hello, 

    Someone from Nordic can point you to their official examples, here's how I did it at Ruuvi:

    https://blog.ruuvi.com/ruuvi-firmware-part-11-scheduler-c95836f3105c

    That blog is a part of lot larger series and quite heavy to grasp it on its own. 

    In essence the timer interrupt adds call to data update function to Nordic scheduler, and the timer interrupt brings the tag out of the sleep. 

    First thing once tag is out of the sleep is to execute scheduled function, including data update scheduled above. 

    After scheduler has run the main loop calls yield() which in turn will call the Nordic power management function. In your case I'd add calls to switch off the mofsets in yield and switch on once the tag has exited Nordic power management. 

    You don't necessarily need to use the scheduler, just having timer interrupt is enough to bring tag out of the sleep. However I'd prefer to not run the sensor reads in timer interrupt context, as it could mask other interrupts such as SPI data ready and lock your program.

  • You can use an RTC to wake the system up from WFE sleep, the watchdog timeout inserts an unnecessary reset in between, which if I understood correctly is something you could avoid. Look at the example provided at nRF5_SDK_15.3.0_59ac345\examples\peripheral\rtc\main.c

Related