<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How to start with sleepy code in nRF connect Desktop SDK</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/109124/how-to-start-with-sleepy-code-in-nrf-connect-desktop-sdk</link><description>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</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 13 Mar 2024 14:16:38 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/109124/how-to-start-with-sleepy-code-in-nrf-connect-desktop-sdk" /><item><title>RE: How to start with sleepy code in nRF connect Desktop SDK</title><link>https://devzone.nordicsemi.com/thread/473683?ContentTypeID=1</link><pubDate>Wed, 13 Mar 2024 14:16:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d90dee49-42ba-4da8-883d-6a9bcfa4dfbf</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;As I mentionned before, the CPU will sleep by default as long as you don&amp;#39;t do anything. But if any peripherals etc are enabled, they will continue to be. What do you use in your application? A typical problem is UART if you have logging enabled. So the first thing you should make sure is to disable logging, by adding configs like these:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_CONSOLE=n
CONFIG_UART_CONSOLE=n
CONFIG_SERIAL=n
CONFIG_LOG=n&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to start with sleepy code in nRF connect Desktop SDK</title><link>https://devzone.nordicsemi.com/thread/473652?ContentTypeID=1</link><pubDate>Wed, 13 Mar 2024 13:12:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:431772e2-6fde-48b0-a9ed-b53930b14de0</guid><dc:creator>Pranathi CH</dc:creator><description>&lt;p&gt;I am using the nRF52840 development kit for my evaluation.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I currently bought it to 150 uA by using thi function (previously it was 4.8mA).&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;strong&gt;pm_device_action_run(cons, PM_DEVICE_ACTION_SUSPEND);&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;in the main thread with K_sleep of 1000 micro seconds.&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;I want to reduce the current consumtion from 150 uA, for which I was going through the datasheet&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/Screenshot-2024_2D00_03_2D00_13-184036.png" /&gt;&lt;/div&gt;
&lt;div&gt;I could see different sleep modes for the nRF52840 board, how do I enable them?&lt;/div&gt;
&lt;div&gt;Could you please provide me some reference to this? or suggest me a example code releted to enabling these sleep modes?&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to start with sleepy code in nRF connect Desktop SDK</title><link>https://devzone.nordicsemi.com/thread/473545?ContentTypeID=1</link><pubDate>Wed, 13 Mar 2024 05:40:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:decef981-b77b-4992-b516-893bc6f0ad15</guid><dc:creator>Pranathi CH</dc:creator><description>&lt;p&gt;&lt;span&gt;Thank you for your comprehension and guidance. I will notify you once I have completed the mentioned procedure.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to start with sleepy code in nRF connect Desktop SDK</title><link>https://devzone.nordicsemi.com/thread/473451?ContentTypeID=1</link><pubDate>Tue, 12 Mar 2024 13:34:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e12ba8dd-e42e-45f6-b90a-5996feb4cb9d</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;I understand. I am not interested in your logic, but if you measure a unexpected high current consumption and want input on what oculd cause it I need to know more about the application you run, the hardweare you are testing on and how you measure.&lt;/p&gt;
&lt;p&gt;So, if you would like to proceed, I suggest the following:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Test with a simple application that has logging disabled and does nothing other than either return from main or have an empty main loop with a k_sleep with a long delay. This way, the CPU should sleep for a long time and no peripherals that can consume significant amount of power will be active.&lt;/li&gt;
&lt;li&gt;Measure the current consumption of that to get the base of your device.&lt;/li&gt;
&lt;li&gt;Is that much higher than expected? If so, we need to first look at&amp;nbsp; your hardware and measurment setup.&lt;/li&gt;
&lt;li&gt;Is it in the order of a few micro amps (which is expected)? If so, we need to look at your firmware to understand why you get an unexpected current consumption.&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to start with sleepy code in nRF connect Desktop SDK</title><link>https://devzone.nordicsemi.com/thread/473441?ContentTypeID=1</link><pubDate>Tue, 12 Mar 2024 13:22:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:444745b2-25da-4842-9d90-79b50d41c2a8</guid><dc:creator>Pranathi CH</dc:creator><description>&lt;p&gt;My actual code consists the logic, I just shared you the syntax of where I was using the sleep.&lt;/p&gt;
&lt;p&gt;And I didn&amp;#39;t check the current consumptions with the code as it is I provided in the above reply, I checked the currents&amp;nbsp; with my logic in it. That&amp;#39;s why I have mentioned &amp;quot;my code&amp;quot; and &amp;quot;my logic&amp;quot; so that you can understand that there is some logic I have written there which I couldn&amp;#39;t share in the dev zone as it is irrelevant.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to start with sleepy code in nRF connect Desktop SDK</title><link>https://devzone.nordicsemi.com/thread/473439?ContentTypeID=1</link><pubDate>Tue, 12 Mar 2024 13:15:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:98488891-5e51-450b-9aa9-2ca94d749e09</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;I see. Nothing obviously stands out here. If you comment out your logic and keep only the sleep, what current consumption do you measure then? If that is also high, you need to look somewhere else. Either in other parts of the application, or it oculd also be worth looking at your hardware and how you measure the current consumption.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to start with sleepy code in nRF connect Desktop SDK</title><link>https://devzone.nordicsemi.com/thread/473436?ContentTypeID=1</link><pubDate>Tue, 12 Mar 2024 13:05:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1689b179-a19f-41dd-8469-b9e16d7670f8</guid><dc:creator>Pranathi CH</dc:creator><description>&lt;p&gt;I am using a thread that is defined as&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;strong&gt;K_THREAD_DEFINE(control, 1024, control_thread, NULL, NULL, NULL, -1, 0, 1000);&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;And at the end of the entry &amp;quot;control_thread&amp;quot; function I am using&amp;nbsp;&lt;span&gt;k_sleep&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;K_MSEC&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;50&lt;/span&gt;&lt;span&gt;));&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int main(void)
{
    #My code#
    
    return 0;
}

void control_thread(void)
{
    while(true)
    {
        #My logic#
        k_sleep(K_MSEC(50));
    }
}

K_THREAD_DEFINE(control, 1024, control_thread, NULL, NULL, NULL, -1, 0, 1000);&lt;/pre&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to start with sleepy code in nRF connect Desktop SDK</title><link>https://devzone.nordicsemi.com/thread/473431?ContentTypeID=1</link><pubDate>Tue, 12 Mar 2024 12:57:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6d4b1c0f-ea29-4984-819b-60cd454ac097</guid><dc:creator>Einar Thorsrud</dc:creator><description>[quote user="Pranathi CH"]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?[/quote]
&lt;p&gt;No, that is not how it works. If you don&amp;#39;t want the main thread (or any other thread for that matter) anymore, just let it return. The idle task always runs.&lt;/p&gt;
[quote user="Pranathi CH"]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.[/quote]
&lt;p&gt;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.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to start with sleepy code in nRF connect Desktop SDK</title><link>https://devzone.nordicsemi.com/thread/473404?ContentTypeID=1</link><pubDate>Tue, 12 Mar 2024 11:51:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1925acca-1dd6-4a82-a763-d23db85ccdb8</guid><dc:creator>Pranathi CH</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;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?&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to start with sleepy code in nRF connect Desktop SDK</title><link>https://devzone.nordicsemi.com/thread/473403?ContentTypeID=1</link><pubDate>Tue, 12 Mar 2024 11:39:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:740e76c2-422d-404b-b7c0-a2fe6dcb54da</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;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).&lt;/p&gt;
&lt;p&gt;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&amp;nbsp;proivde many APIs for that (see &lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/kernel/services/timing/clocks.html"&gt;Kernel Timing&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;For isntance, you can make threads thta sleep and wake up every &lt;em&gt;x&lt;/em&gt; amount of time, or threads that sleep because of soemthing else, or you can use dalayed items in a &lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/kernel/services/threads/workqueue.html"&gt;workqueue&lt;/a&gt; in order to schedule work to be done at a specific time in the future.&lt;/p&gt;
&lt;p&gt;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 &lt;a href="https://academy.nordicsemi.com/courses/nrf-connect-sdk-fundamentals/"&gt;nRF Connect SDK Fundamentals&lt;/a&gt;&amp;nbsp;course, which I suggest you look at when it is available (you should also look at the Fundamentals course if you have not).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to start with sleepy code in nRF connect Desktop SDK</title><link>https://devzone.nordicsemi.com/thread/473392?ContentTypeID=1</link><pubDate>Tue, 12 Mar 2024 10:23:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:89a07992-4795-44ca-aab6-3e966ec4cb87</guid><dc:creator>Pranathi CH</dc:creator><description>&lt;p&gt;As per my previous reply, my requirement is:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;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).&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Pranathi&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to start with sleepy code in nRF connect Desktop SDK</title><link>https://devzone.nordicsemi.com/thread/473201?ContentTypeID=1</link><pubDate>Mon, 11 Mar 2024 13:35:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:47238834-26ff-4891-a316-2572c1221ba8</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You can for instance refer to the &lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/samples/basic/blinky/README.html"&gt;Blinky sample&lt;/a&gt;. 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.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to start with sleepy code in nRF connect Desktop SDK</title><link>https://devzone.nordicsemi.com/thread/473188?ContentTypeID=1</link><pubDate>Mon, 11 Mar 2024 13:17:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ff2254cb-b2be-4979-a8c5-6adf6ff9268f</guid><dc:creator>Pranathi CH</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Can you provide me a sample code for some clear refernece for my side?&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Pranathi.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to start with sleepy code in nRF connect Desktop SDK</title><link>https://devzone.nordicsemi.com/thread/473170?ContentTypeID=1</link><pubDate>Mon, 11 Mar 2024 12:37:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cbb86712-580a-4ad5-b683-e24f9c089370</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Th enRF Connect SDK includes the Zephyr RTOS, where there is always a&amp;nbsp;idle thread that enters sleep mode when idle. So you do not need to do anything special to enter sleep, other than don&amp;#39;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.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to start with sleepy code in nRF connect Desktop SDK</title><link>https://devzone.nordicsemi.com/thread/473148?ContentTypeID=1</link><pubDate>Mon, 11 Mar 2024 11:20:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b6cb5e83-c45a-4579-a4c3-360088eaf909</guid><dc:creator>Pranathi CH</dc:creator><description>&lt;p&gt;Can you refer me a timer based sleep code?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>