Hi Team,
How to start with the sleepy code in nRF connect desktop SDK, can anyone provide me a refernce which has clear insights?
Thanks,
Pranathi
Hi Team,
How to start with the sleepy code in nRF connect desktop SDK, can anyone provide me a refernce which has clear insights?
Thanks,
Pranathi
Hi,
Th enRF Connect SDK includes the Zephyr RTOS, where there is always a idle thread that enters sleep mode when idle. So you do not need to do anything special to enter sleep, other than don't do anything. Note that for instance having a main loop that runs continiously means using the CPU at all times, so if you do, you can for instance wait with k_sleep() to sleep for a specified ammount of time.
Hi,
Can you provide me a sample code for some clear refernece for my side?
I want to use a timer based sleep mechanism as such I want the board to wake up when I am trying to exhibit a functionlity and after executing it my board should go into sleep and wake up when the said functionlity to be executed. And FYI I am using nRF52840 DK.
Thanks,
Pranathi.
Hi,
Can you provide me a sample code for some clear refernece for my side?
I want to use a timer based sleep mechanism as such I want the board to wake up when I am trying to exhibit a functionlity and after executing it my board should go into sleep and wake up when the said functionlity to be executed. And FYI I am using nRF52840 DK.
Thanks,
Pranathi.
Hi,
You can for instance refer to the Blinky sample. This toggles a ledd in a loop and sleeps in between. As nothing else is happening, the system automatically enters system ON low power mode during this time.
As per my previous reply, my requirement is:
My nRF should be in sleep all the time and it should wakeup when I want to implement a funcitonlity and this wakeup should happen with the help of a timer (as in we have 4 timers or 5 timers in nRF52840).
But in the blinky example I am more like in control with the sleep functionlity rather than in control with my functions I want to execute. by default, I want my board to be in sleep mode and by utilizing the timers (TIMER0/TIMEER1/TIMER2/TIMER3..) I want to wake the board up and after it wakes up I want to implement my functions and put my board back to sleep mode.
Thanks,
Pranathi
Hi,
They key point regardign sleep is that you can forget about the sleep, as that is handled automatically. Whenever you do not do anything, the kernel automatically ensures that the device sleeps in sytem ON low power mode (waiting for events/interrupts).
Note that the timers you describe are not low power, and they are normally never used while in sleep. Instead, an RTC instance is used for keeping track of time, and that is handled for you by the Zephyr kernel, which proivde many APIs for that (see Kernel Timing).
For isntance, you can make threads thta sleep and wake up every x amount of time, or threads that sleep because of soemthing else, or you can use dalayed items in a workqueue in order to schedule work to be done at a specific time in the future.
We are finishing up a more advanced course on this that we plan to release shortly, which I recomend you take a look at (this is indended as a natural continuation of nRF Connect SDK Fundamentals course, which I suggest you look at when it is available (you should also look at the Fundamentals course if you have not).
Hi,
Can I use k_sleep(K_FOREVER) in my code (in main) to make my system go in constant sleep and then use an RTC as a wakeup source to wake the core of my system?
I am getting around 5mA of current consumption without any sleep exhibited and I am aiming to reduce the current consumption for a better battery life.
Pranathi CH said:Can I use k_sleep(K_FOREVER) in my code (in main) to make my system go in constant sleep and then use an RTC as a wakeup source to wake the core of my system?
No, that is not how it works. If you don't want the main thread (or any other thread for that matter) anymore, just let it return. The idle task always runs.
Pranathi CH said:I am getting around 5mA of current consumption without any sleep exhibited and I am aiming to reduce the current consumption for a better battery life.
Can you share what you are doing? If for instance you have an eternal loop with no sleep so that the CPU is on 100% that could give you numbers of that magnitude.