<?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>No sleep during nrf_drv_twi_rx with LIS3DH</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/75330/no-sleep-during-nrf_drv_twi_rx-with-lis3dh</link><description>I have been converting my TWI calls to be asynchronous by specifying a twi_handler, but my NRF52840 does not sleep during the TWI calls. 
 I use SDK15.3 and s140 softdevice. (I plan to upgrade to SDK17 soon) 
 When reading the 32 latest XYZ values (192</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 21 May 2021 06:23:41 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/75330/no-sleep-during-nrf_drv_twi_rx-with-lis3dh" /><item><title>RE: No sleep during nrf_drv_twi_rx with LIS3DH</title><link>https://devzone.nordicsemi.com/thread/310909?ContentTypeID=1</link><pubDate>Fri, 21 May 2021 06:23:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:33897550-3934-4f4e-aa4d-c6bd99423ccc</guid><dc:creator>Jason</dc:creator><description>&lt;p&gt;Oh wow, yes, good point! Thanks.&lt;/p&gt;
&lt;p&gt;I might have been temped to waste even more time trying to&amp;nbsp;check it needlessly.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No sleep during nrf_drv_twi_rx with LIS3DH</title><link>https://devzone.nordicsemi.com/thread/310899?ContentTypeID=1</link><pubDate>Fri, 21 May 2021 05:34:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:39bbc129-a810-4780-ab46-696675b64929</guid><dc:creator>Nguyen Hoan Hoang</dc:creator><description>&lt;p&gt;192Bytes in 5ms -&amp;gt; 38KBytes/s -&amp;gt; 384KBits/s. &amp;nbsp;Your speed setting is 400KHz. You are get 384Kbits/s which is correct.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No sleep during nrf_drv_twi_rx with LIS3DH</title><link>https://devzone.nordicsemi.com/thread/310896?ContentTypeID=1</link><pubDate>Fri, 21 May 2021 05:06:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e41c9f58-9ebb-43d7-ae8c-21cf096dd58c</guid><dc:creator>Jason</dc:creator><description>&lt;p&gt;I also think that I must have a communication problem with the LIS3DH because 5ms for 192 bytes implies ~38kbps.The datasheet has specific instructions about the i2c protocol it expects, but it is not obvious to me how the nrf_drv_twi calls might deviate from their expectations.&lt;/p&gt;
&lt;p&gt;But 10Mhz seems far better than 400khz.&amp;nbsp;and certainly better than 38kbps.&amp;nbsp;So I think this is the best way to eliminate this problem. I can breadboard it using the Sparkfun LIS3DH board.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In fact I&amp;#39;ve also ordered the newer&amp;nbsp;&lt;a href="https://www.st.com/en/mems-and-sensors/ais2dw12.html"&gt;https://www.st.com/en/mems-and-sensors/ais2dw12.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.arrow.com/en/products/steval-mki206v1/stmicroelectronics"&gt;https://www.arrow.com/en/products/steval-mki206v1/stmicroelectronics&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It claims even lower&amp;nbsp;current and I think it might have lower noise levels.&lt;/p&gt;
&lt;p&gt;Thanks again for your help&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No sleep during nrf_drv_twi_rx with LIS3DH</title><link>https://devzone.nordicsemi.com/thread/310858?ContentTypeID=1</link><pubDate>Thu, 20 May 2021 19:21:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8693faf7-33a9-4bbe-a110-a6f98b363da2</guid><dc:creator>Jason</dc:creator><description>&lt;p&gt;I am not aware of anything else which might be running.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;My earlier test showed that the LIS3DH draws ~1mA during this process. So based on your figures, I think we should see a combined ~3.5mA. (instead of ~8mA at the moment.)&lt;/p&gt;
&lt;p&gt;Neither figure is really low enough and perhaps it would be better to use SPI&amp;nbsp;instead of TWI. The LIS3DH supports SPI at 10Mhz.&amp;nbsp;Do you expect this would use use less power?&lt;/p&gt;
&lt;p&gt;Thanks again for your help.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No sleep during nrf_drv_twi_rx with LIS3DH</title><link>https://devzone.nordicsemi.com/thread/310789?ContentTypeID=1</link><pubDate>Thu, 20 May 2021 13:49:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0553d280-f9a1-4460-94ee-15118ad6c710</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The CPU seems to be in sleep mode for most of the time.&lt;/p&gt;
&lt;p&gt;Any current going through the pull-resistors should not be much higher than ~1 mA, and the sleep current with an active TWIM (w/DMA) should be around 1.5 mA.&lt;/p&gt;
&lt;p&gt;The 192 bytes should be read in one transaction, but you have several wake-ups within this TWIM reception. Is there anything else running in your system while this process is on-going?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No sleep during nrf_drv_twi_rx with LIS3DH</title><link>https://devzone.nordicsemi.com/thread/310782?ContentTypeID=1</link><pubDate>Thu, 20 May 2021 13:30:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f510e1a0-0440-4a5d-80f8-d3595ec0b86a</guid><dc:creator>Jason</dc:creator><description>&lt;p&gt;Hi Hakon, did you see my comment below? I am not sure if you receive notifications for comments or just replies.&lt;/p&gt;
&lt;p&gt;I do not understand why the current is so high when the NRF52840 is sleeping.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No sleep during nrf_drv_twi_rx with LIS3DH</title><link>https://devzone.nordicsemi.com/thread/310651?ContentTypeID=1</link><pubDate>Thu, 20 May 2021 09:15:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:47ecef18-5363-42b8-a7ca-d1390b51bc83</guid><dc:creator>Jason</dc:creator><description>&lt;p&gt;There was no race condition.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve made some significant progress that maybe you can help me with.&lt;/p&gt;
&lt;p&gt;I changed the code to perform the first 3 (of 4) twi calls synchronously, and the&amp;nbsp;4th call is the time-consuming one which I run asynchronously.&amp;nbsp;I also hooked up the PPK2 logic analyser to show where the time was spent. See screenshot below&lt;/p&gt;
&lt;p&gt;Pins 0,1,2, show time spent in twi_tx, twi_rx, &lt;span&gt;twi_tx.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Pin 3 show time spent receiving 192 bytes in twi_rx&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Pin 4 shows the time spent processing the samples (moving averages etc)&lt;/p&gt;
&lt;p&gt;Pin 5 shows time spent inside&amp;nbsp;nrf_pwr_mgmt_run. This is the most interesting because it shows that lots of time is spent inside nrf_pwr_mgmt_run() but the current is still high.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/ice_5F00_screenshot_5F00_20210520_2D00_110918.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/ice_5F00_screenshot_5F00_20210520_2D00_110107.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;I expected the current to drop to a few uA&amp;#39;s while the NRF52840 is inside&amp;nbsp;nrf_pwr_mgmt_run()&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I am confused by this result because it seems to show that the code is inside&amp;nbsp;nrf_pwr_mgmt_run but the current is still very high.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No sleep during nrf_drv_twi_rx with LIS3DH</title><link>https://devzone.nordicsemi.com/thread/310597?ContentTypeID=1</link><pubDate>Thu, 20 May 2021 04:11:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eccfdd95-de19-4dfc-a5fc-9af2b4acc5a9</guid><dc:creator>Jason</dc:creator><description>&lt;p&gt;I think I have a race condition because some&amp;nbsp;nrf_drv_twi_ calls respond so quickly. I&amp;nbsp;am working to debug it&amp;nbsp;at the moment.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No sleep during nrf_drv_twi_rx with LIS3DH</title><link>https://devzone.nordicsemi.com/thread/310491?ContentTypeID=1</link><pubDate>Wed, 19 May 2021 13:39:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9b6baa50-560c-4406-81d7-d8a3a368890b</guid><dc:creator>Jason</dc:creator><description>&lt;p&gt;Thanks, they&amp;#39;re all marked as volatile and I don&amp;#39;t get any error codes from the nrf_drv_twi_* calls.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Is there any way to know why it doesn&amp;#39;t enter sleep mode?&lt;/p&gt;
&lt;p&gt;My main loop calls nrf_pwr_mgmt_run() immediately after the&amp;nbsp;&lt;span&gt;&amp;nbsp;nrf_drv_twi_* calls.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/ice_5F00_screenshot_5F00_20210519_2D00_151540.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;When I look at sd_app_evt_wait I see this comment about interrupts. The 2nd note sounds relevant.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/ice_5F00_screenshot_5F00_20210519_2D00_153523.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Obviously I cannot step into sd_app_evt_wait.&lt;/p&gt;
&lt;p&gt;Could the calls to&amp;nbsp;&lt;span&gt;&amp;nbsp;nrf_drv_twi_* have immediately caused an interrupt?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;It&amp;#39;s really only the call to get eh 192 bytes of accelerometer data that I really care about and it appears to take &amp;gt;5ms to complete.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: No sleep during nrf_drv_twi_rx with LIS3DH</title><link>https://devzone.nordicsemi.com/thread/310455?ContentTypeID=1</link><pubDate>Wed, 19 May 2021 12:51:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e785bcc5-eb03-46e4-8a39-78133a62701d</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;in your twi_handler, you should check the evt type to see if there&amp;#39;s an error that has occurred.&lt;/p&gt;
&lt;p&gt;You should also check the return code from the nrf_drv_twi_* calls.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Since you mention timers, and twi callbacks, you should look into declaring any variables incremented/set in those to volatile.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>