<?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>TWI causing nRF52 not to sleep</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/16069/twi-causing-nrf52-not-to-sleep</link><description>I am using sd_app_evt_wait() to put my nRF52 to sleep. Works fine except after I read from a TWI sensor. As soon as I do I see the nRF52 continuously jump out of sleep. I have put a log into my twi_handler and except when I write to/read from the sensor</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 31 Aug 2016 11:27:23 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/16069/twi-causing-nrf52-not-to-sleep" /><item><title>RE: TWI causing nRF52 not to sleep</title><link>https://devzone.nordicsemi.com/thread/61286?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2016 11:27:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7fd2c076-8d6d-40e5-9fa4-aff609835b0f</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;RK, you are talking about &lt;a href="https://devzone.nordicsemi.com/question/44476/nrf52-softdevice-s132-use-of-fpu/#44576"&gt;this&lt;/a&gt; case?. That issue was in 1.0.0.3_alpha&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI causing nRF52 not to sleep</title><link>https://devzone.nordicsemi.com/thread/61291?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2016 10:27:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:335bed4e-a69c-41d7-9f46-1bfc995bff54</guid><dc:creator>RichieJH</dc:creator><description>&lt;p&gt;So after much investigation it was a float calculation that was being performed immediately after the TWI reading that was causing the nRF52 to stay awake.  Adding the following power manage function solved it&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void power_manage(void)
{

    uint32_t err_code;
    __set_FPSCR(__get_FPSCR()  &amp;amp; ~(FPU_EXCEPTION_MASK));      
    (void) __get_FPSCR();
    NVIC_ClearPendingIRQ(FPU_IRQn);

    err_code = sd_app_evt_wait();
    APP_ERROR_CHECK(err_code);
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI causing nRF52 not to sleep</title><link>https://devzone.nordicsemi.com/thread/61285?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2016 10:24:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0c80396c-f2e0-4668-9e2e-be1c85bc939c</guid><dc:creator>RichieJH</dc:creator><description>&lt;p&gt;Yes indeed.  nRF52 header wasn&amp;#39;t included.  Now included, and power_manage() now working.  Thanks RK.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI causing nRF52 not to sleep</title><link>https://devzone.nordicsemi.com/thread/61284?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2016 10:10:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9e28ca5a-3166-4da1-98e9-e2747feff338</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;well that&amp;#39;s rather unfortunate then isn&amp;#39;t it as we might have solved this yesterday. FPU_IRQn is defined by the nrf52 header file so of course you have it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI causing nRF52 not to sleep</title><link>https://devzone.nordicsemi.com/thread/61283?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2016 10:02:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:19c9f06c-47fa-49e2-bd2a-1251788334e5</guid><dc:creator>RichieJH</dc:creator><description>&lt;p&gt;Oops I think I know why the log was showing no interrupt.  I am running an LED timer initially and that may have been the trigger at the time, not this issue.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI causing nRF52 not to sleep</title><link>https://devzone.nordicsemi.com/thread/61282?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2016 09:59:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:95bb2b2a-0381-4337-83c6-c740b7f78483</guid><dc:creator>RichieJH</dc:creator><description>&lt;p&gt;Yes, see above my original question about the flag clearing.  The issue I have is:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;FPU_IRQn
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;does not appear defined from SES&amp;#39;s perspective.  So I was wondering how I could define it.&lt;/p&gt;
&lt;p&gt;Also I don&amp;#39;t know about the logs, I&amp;#39;m almost certain the second one was at a break point on a printf immediately below &lt;code&gt;sd_app_evt_wait()&lt;/code&gt; (i.e., immediately having returned from whatever took it out of the sleep function).  I can take another snapshot shortly.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI causing nRF52 not to sleep</title><link>https://devzone.nordicsemi.com/thread/61281?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2016 09:53:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e0e7d18e-176b-4c28-bc5c-862755267b7b</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;There&amp;#39;s a suggested flag clearing to do before you call sd_app_evt_wait(). If that does turn out to be the case however the register dumps you posted earlier were very misleading, in fact wrong, as they show there are no exceptions pending.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI causing nRF52 not to sleep</title><link>https://devzone.nordicsemi.com/thread/61280?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2016 09:50:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4179fb11-b8f1-4183-b668-4cbffbae643b</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;put FPU in the search box and see if anything we&amp;#39;ve talked about before gives a hint. There&amp;#39;s soemthing about FTU in the release notes or the documentation somewhere too.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI causing nRF52 not to sleep</title><link>https://devzone.nordicsemi.com/thread/61279?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2016 09:49:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c52f34ca-662c-45ad-99bc-9d858ae371b4</guid><dc:creator>RichieJH</dc:creator><description>&lt;p&gt;If I simply do this in main above the loop:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;float divider = 6.66;
float test = 10 / divider;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It&amp;#39;s enough to keep the nRF52 awake. Very strange.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI causing nRF52 not to sleep</title><link>https://devzone.nordicsemi.com/thread/61278?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2016 09:41:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1bdc6500-026d-401c-9ac0-3f760c3cd379</guid><dc:creator>RichieJH</dc:creator><description>&lt;p&gt;132 v 2 for SD&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI causing nRF52 not to sleep</title><link>https://devzone.nordicsemi.com/thread/61277?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2016 09:37:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c6591d47-1876-413d-85b4-0be45bb39f5e</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;The constant waking is usually when there&amp;#39;s an FP error, as far as I remember from the release notes and the other threads about this. The FP interrupt is raised and never cleared. What SD version?&lt;/p&gt;
&lt;p&gt;@aryan am I remembering this correctly, or was there another FPU issue.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI causing nRF52 not to sleep</title><link>https://devzone.nordicsemi.com/thread/61276?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2016 09:35:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:821bbabd-c977-4400-a8f2-02dca227bed9</guid><dc:creator>RichieJH</dc:creator><description>&lt;p&gt;I don&amp;#39;t know either.  It&amp;#39;s just with that calculation commented out, sleep is maintained.  With that calculation in, continual waking is observed.  I also did a little tester float divider calculation and the same thing happened.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI causing nRF52 not to sleep</title><link>https://devzone.nordicsemi.com/thread/61275?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2016 09:29:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:10ed688c-a730-4be5-aac1-0263e86e6ebd</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;well that makes no sense, I know I suggested FPU might be an issue however there&amp;#39;s nothing wrong with that calculation and the flags in the text you posted earlier said there were no FP exceptions.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI causing nRF52 not to sleep</title><link>https://devzone.nordicsemi.com/thread/61274?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2016 09:27:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:902d3d3a-7ff7-474d-92c0-81f5bd4d4910</guid><dc:creator>RichieJH</dc:creator><description>&lt;p&gt;Ok, so it does indeed look like a floating point calculation I was doing immediately having read from the sensor.  So the continual wake has noting to do with the TWI itself.  I have tried to play around with casting to get the calculation with the resolution I need without luck.  Essentially I need to achieve this with the nRF52 being able to go to sleep afterwards:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;float tempRH = ((125 * float_humidity) / 65336) - 6;
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI causing nRF52 not to sleep</title><link>https://devzone.nordicsemi.com/thread/61273?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2016 08:28:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2940c42b-622d-4eb8-b862-46301f70d3d0</guid><dc:creator>RichieJH</dc:creator><description>&lt;p&gt;Just in case it is FPU I thought I would clear any interrupts, however FPU_IRQn is showing as not defined in SES.  Amended question above.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI causing nRF52 not to sleep</title><link>https://devzone.nordicsemi.com/thread/61270?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2016 07:39:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6dce4fb9-c342-4451-9686-5c106105bf3b</guid><dc:creator>RichieJH</dc:creator><description>&lt;p&gt;Thanks.  How to I set-up breakpoints in that file using Segger Embedded Studio?  It seems to be set up as a package file for SES and when I remove it from the project macros to add the file separately to enable me to add the breakpoints SES throws up an error.  I have a delay between writing and reading from the sensor and its a shared bus with another sensor which I am not using in this application.  Just for further information.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI causing nRF52 not to sleep</title><link>https://devzone.nordicsemi.com/thread/61287?ContentTypeID=1</link><pubDate>Tue, 30 Aug 2016 11:31:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:65c63c1e-aef8-43b3-b745-6b45e0da7cb7</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;breakpoint in interrupt_handlers should clarify that. Also you can try to see if any fault exception happened by putting breakpoints in the default handlers defined in arm_startup_nrf52.s file&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI causing nRF52 not to sleep</title><link>https://devzone.nordicsemi.com/thread/61289?ContentTypeID=1</link><pubDate>Tue, 30 Aug 2016 11:13:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f5661dda-31ef-40de-bffe-a40f0be84abb</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;I assumed that register state was after the sd_app_evt_wait() has returned so that would be after the interrupts (if there were any) had been serviced. If one wasn&amp;#39;t cleared then it wouldn&amp;#39;t ever get out of the interrupt handlers and return, so it&amp;#39;s not that. It would have to be a pretty fast interrupt to keep the thing awake, does the twi driver use a timer for anything, wondered if it was a fast timeout timer which wasn&amp;#39;t getting suppressed and was constantly waking it up&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI causing nRF52 not to sleep</title><link>https://devzone.nordicsemi.com/thread/61288?ContentTypeID=1</link><pubDate>Tue, 30 Aug 2016 11:05:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f4c89cc1-6b7c-49da-a0dd-b5e5c481a83f</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;I cannot see any pending interrupts either. Are you sure that you are sniffing the registers before the interrupt is serviced?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI causing nRF52 not to sleep</title><link>https://devzone.nordicsemi.com/thread/61272?ContentTypeID=1</link><pubDate>Tue, 30 Aug 2016 08:39:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a4161057-4bef-433a-b959-18ed812fb57d</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;I don&amp;#39;t see anything there either. I thought it might be the FPU exception but it&amp;#39;s not, there&amp;#39;s none shown. So I don&amp;#39;t know why it keeps bumping out of sleep&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI causing nRF52 not to sleep</title><link>https://devzone.nordicsemi.com/thread/61271?ContentTypeID=1</link><pubDate>Tue, 30 Aug 2016 07:24:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2160b3bd-49e0-4917-89e6-cf3c925dfe65</guid><dc:creator>RichieJH</dc:creator><description>&lt;p&gt;Thanks RK.  OK checking the Registers in Segger Embedded Studio shows that there are no obvious interrupts causing the nRF52 not to hold in sd_app_evt_wait().  I attach the txt outputs in my original question.  The first one is when no sensor reading is begun.  The second is after a sensor reading at the point immediately after &lt;code&gt;sd_app_evt_wait()&lt;/code&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI causing nRF52 not to sleep</title><link>https://devzone.nordicsemi.com/thread/61290?ContentTypeID=1</link><pubDate>Tue, 30 Aug 2016 00:49:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:53bf2b83-27eb-4a9a-9bb1-3360a4621580</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;What interrupts are pending when it comes out of sleep mode? Look at the interrupt registers, all of them, including the standard cortex ones (like FPU).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>