<?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>nRF51422 won&amp;#39;t sleep</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/10424/nrf51422-won-t-sleep</link><description>I am trying to get my system with a hardware RTC generating periodic interrupts every 30 seconds to sleep between interrupts. I&amp;#39;ll paste the code below, but here is the problem: 
 I get the interrupts signalled to my PORT event handler and, in my loop</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 09 Dec 2015 08:55:02 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/10424/nrf51422-won-t-sleep" /><item><title>RE: nRF51422 won't sleep</title><link>https://devzone.nordicsemi.com/thread/38739?ContentTypeID=1</link><pubDate>Wed, 09 Dec 2015 08:55:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:25b7265f-9e0c-4026-85b7-eaa878ec3ce3</guid><dc:creator>Radoslaw Koppel</dc:creator><description>&lt;p&gt;In this very situation we really wants to be sure that every event is cleared just before calling __WFE and it is good example for using SEV, WFE, WFE sequence. But please read also my comment here: &lt;a href="https://devzone.nordicsemi.com/question/1555/how-do-you-put-the-nrf51822-chip-to-sleep/?comment=60256#comment-60256"&gt;devzone.nordicsemi.com/.../&lt;/a&gt; before implementing it into your code. This sequence may not be safe.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51422 won't sleep</title><link>https://devzone.nordicsemi.com/thread/38738?ContentTypeID=1</link><pubDate>Tue, 24 Nov 2015 13:28:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2abe9d66-3a9b-4f31-a201-be3a35f2c07c</guid><dc:creator>TomWS</dc:creator><description>&lt;p&gt;Yes, this last explanation is perfect!  Thank you for helping me understand!
Tom&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51422 won't sleep</title><link>https://devzone.nordicsemi.com/thread/38737?ContentTypeID=1</link><pubDate>Tue, 24 Nov 2015 12:43:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:64faa82f-8f1a-4e30-9d85-fbc417f6131f</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;I am glad to hear this fixed your problem. The thing is that if nothing else is done in the main loop, as is often the case in a purely  event driven application, then the order does not matter as it will basically result in the same set of instructions (except for the relative position of the jump). However, when you do other stuff in your main loop you have to get the order right.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51422 won't sleep</title><link>https://devzone.nordicsemi.com/thread/38736?ContentTypeID=1</link><pubDate>Tue, 24 Nov 2015 12:34:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a4811e82-c295-411e-823f-8245cab42920</guid><dc:creator>TomWS</dc:creator><description>&lt;p&gt;Doh!  Actually, this makes total sense to me, however, throughout this forum all the examples seemed to be the sequence that I originally used.  I&amp;#39;ve reordered as you&amp;#39;ve suggested and, indeed, it DOES SLEEP!!! YAY!  Thank you very much!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51422 won't sleep</title><link>https://devzone.nordicsemi.com/thread/38735?ContentTypeID=1</link><pubDate>Tue, 24 Nov 2015 12:21:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fb4d9b5a-038d-4aa7-847f-2010d97f392e</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Probably the problem is the way your code attempts to go to sleep. You are using this code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    // Enter System ON sleep mode
    __WFE();
    // Make sure any pending events are cleared
    __SEV();
    __WFE();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But this will probably not do what you think. If we &lt;em&gt;assume that a event is pending&lt;/em&gt;, then the first WFE (Wait for Event) instruction will not do what you expect, as the pending event will cause the CPU to wake up again immediately. Then the SEV (Send Event) instruction will signal an event to the CPU. Again, the CPU will wake up immediatly from the next WFE as a event is pending.&lt;/p&gt;
&lt;p&gt;The correct order is this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    // Make sure any pending events are cleared
    __SEV();
    __WFE();
    // Enter System ON sleep mode
    __WFE();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here the SEV will make sure that a event is set, in case it is not. The first WFE will make sure the event is cleared. Thus after those two instructions we can be confident that there are no pending events. The last WFE will put the CPU to sleep.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51422 won't sleep</title><link>https://devzone.nordicsemi.com/thread/38734?ContentTypeID=1</link><pubDate>Tue, 24 Nov 2015 11:38:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1be46cad-b2f0-4627-a455-6f37e08249dc</guid><dc:creator>TomWS</dc:creator><description>&lt;p&gt;Yes, my mistake on this part of the problem.  I had been shutting down after program load and restarting with the SEGGER disconnected, but hadn&amp;#39;t noticed any difference previously (probably because it&amp;#39;s not sleeping in the first case), so didn&amp;#39;t think it mattered.  In this second case, I retried it and, once disconnected and restarted, the total board current is a respectable 2.5uA.&lt;/p&gt;
&lt;p&gt;Thank you for pointing this out.  However, what I&amp;#39;d really like to know is why the first piece of code won&amp;#39;t sleep.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51422 won't sleep</title><link>https://devzone.nordicsemi.com/thread/38733?ContentTypeID=1</link><pubDate>Tue, 24 Nov 2015 10:27:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1a7f48e0-4f94-4f8c-aa3c-147034e542c2</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Are you using a debugger (RTT printing etc.) when you say that power consumption is 2.3mA? when powered down? When measuring power consumption you should not use a debugger (this also means that you have to do a pin reset after programming before measuring), as the debugger interface consumes approximatly 1.2 mA.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>