<?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>NRF_TWIM_IS_BUSY is taking up to 12ms to return</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/46733/nrf_twim_is_busy-is-taking-up-to-12ms-to-return</link><description>Hi, 
 I am using an nrf52840 on a custom board with the 6.0 softdevice and 15.0 sdk. The I2C bus is running at 400khz. 
 I am reading 4 bytes on the i2c bus. The initial write to pass the register address takes about 90us for the bus to not be busy. The</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 02 May 2019 22:17:06 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/46733/nrf_twim_is_busy-is-taking-up-to-12ms-to-return" /><item><title>RE: NRF_TWIM_IS_BUSY is taking up to 12ms to return</title><link>https://devzone.nordicsemi.com/thread/185012?ContentTypeID=1</link><pubDate>Thu, 02 May 2019 22:17:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:55b309ef-ce08-471c-b7b4-ed31b352819b</guid><dc:creator>paul</dc:creator><description>&lt;p&gt;Thanks Einar,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; yeah I am aware of that issue, been bitten before. I believed I needed to copy the data out so needed something to put it in. What was worse it turns out was that I was never actually looking at the value and so never freeing it.&amp;nbsp; As the unfreed buffer count mounted the timing stretched out. This is one of the easy mistakes to do when doing event driven since things happen in many different places.&lt;/p&gt;
&lt;p&gt;Your suggestion to trace it was what finally cracked the problem.&lt;/p&gt;
&lt;p&gt;Many thanks&lt;/p&gt;
&lt;p&gt;Paul&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF_TWIM_IS_BUSY is taking up to 12ms to return</title><link>https://devzone.nordicsemi.com/thread/184832?ContentTypeID=1</link><pubDate>Thu, 02 May 2019 10:39:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:01134c1a-2620-40a1-96e3-91c89323cdcf</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi Paul,&lt;/p&gt;
&lt;p&gt;I was wondering if the slave did clock stretching, but it does not seem like this delay is directly related to TWI or the driver. Rather, you say that you do some work in the event handler (callback), and that could definitely explain this, since the driver waits with setting the internal busy flag to false until after executing the callback.&lt;/p&gt;
&lt;p&gt;It is generally&amp;nbsp;is bad practice to spend much time in the event handlers in the SDK. If you need to much work at this point it is typically better to defer the execution of the work to the main/thread context, for instance using an app scheduler or a simple volatile synchronization variable. This way it will not run in interrupt priority, and the event handler (which is essentially part of the TWI interrupt handling) is made as short as possible.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF_TWIM_IS_BUSY is taking up to 12ms to return</title><link>https://devzone.nordicsemi.com/thread/184659?ContentTypeID=1</link><pubDate>Wed, 01 May 2019 04:29:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0215a150-8b99-44a3-abce-3002bdd84819</guid><dc:creator>paul</dc:creator><description>&lt;p&gt;Hi Einar,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; we don&amp;#39;t own a logic analyser however we have done the following testing:&lt;/p&gt;
&lt;p&gt;1) replicated the problem with an LP5018 LED controller on the same bus and using the same code. It also stretches out to around 13ms&lt;/p&gt;
&lt;p&gt;2) We watched the transaction on the cro with the result:&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;a) 2 bytes written&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;b) 12 bytes returned&lt;/p&gt;
&lt;p&gt;Total time activity on the bus is about 400us. It then takes the rest of the about 13ms&amp;nbsp;in the handler or the wait for busy to say we are not busy.&amp;nbsp; I have attached a couple of photos.&lt;/p&gt;
&lt;p&gt;&amp;lt;code&amp;gt;&lt;/p&gt;
&lt;p&gt;while(1) {&lt;/p&gt;
&lt;p&gt;GPIO_debug_on(true);&lt;br /&gt; byte_read_multi_twi( 0x28, 3, buf, 12);&lt;br /&gt; GPIO_debug_on(false);&lt;br /&gt; nrf_delay_ms(1);&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;&amp;lt;/code&amp;gt;&lt;/p&gt;
&lt;p&gt;the following picture shows the full transaction. The bottom trace is the GPIO pin going high before the call and going low afterwards. The dip is the 1ms delay put in just to make it easier to see where the cycle starts.&lt;/p&gt;
&lt;p&gt;The top trace shows the data line on the i2c bus. As you can see it starts soon after the timing period and then stops and there is a long time of no activity. The actual transation - ie data on the bus - takes 400us which was our rule of thumb expectation it would take.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/IMG_5F00_20190501_5F00_085816.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;This trace shows the activity on the i2c bus. The bottom trace is the clock at 400khz. The top is the data line. This looks like an address, then register, then 12 bytes coming back.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/IMG_5F00_20190501_5F00_092027.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;This trace shows the stop condition at the end of the transfer with both the clock and data line going high.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/IMG_5F00_20190501_5F00_092131.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;We are using nrf_malloc&amp;nbsp;in the twim event handler to copy out the data returned. This is taking the 13ms. Removing the malloc produces this with a 100us delay between reads.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/IMG_5F00_20190501_5F00_102244.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;I guess the question is whether nrf_malloc should be taking up to 13ms to run? At this stage, I have removed the offending code and my sampling cycle has gone down to my target timing.&lt;/p&gt;
&lt;p&gt;Cheers Paul&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF_TWIM_IS_BUSY is taking up to 12ms to return</title><link>https://devzone.nordicsemi.com/thread/184501?ContentTypeID=1</link><pubDate>Tue, 30 Apr 2019 09:21:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e338aa15-8ed6-4977-b6ef-582a0af56d91</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;I see. But I do not understand what is causing this, so it would be interesting to see what is actually happening on the TWI lines. Do you have a logic analyzer trace showing this? It would be even better if you could include the debug GPIO pin you toggle before and after&amp;nbsp;nrfx_twim_is_busy() in the same trace.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF_TWIM_IS_BUSY is taking up to 12ms to return</title><link>https://devzone.nordicsemi.com/thread/184426?ContentTypeID=1</link><pubDate>Tue, 30 Apr 2019 04:53:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:28681426-9f44-4724-821e-0d99acc0460b</guid><dc:creator>paul</dc:creator><description>&lt;p&gt;hi Einar,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; as far as I can see, the chip itself does the following:&lt;/p&gt;
&lt;p&gt;1) reads the value&lt;/p&gt;
&lt;p&gt;2) sets a flag on the chip to say it is done&lt;/p&gt;
&lt;p&gt;3) I then do the read of the results&lt;/p&gt;
&lt;p&gt;4) this read steadily gets longer.&lt;/p&gt;
&lt;p&gt;for what its worth, the chip is an ST vl53l0x time of flight or distance measurerer.&lt;/p&gt;
&lt;p&gt;Cheers Paul&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF_TWIM_IS_BUSY is taking up to 12ms to return</title><link>https://devzone.nordicsemi.com/thread/184406?ContentTypeID=1</link><pubDate>Mon, 29 Apr 2019 22:23:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1fda0ddc-888e-418a-8cb3-302d0b86521a</guid><dc:creator>paul</dc:creator><description>&lt;p&gt;Hi Einar,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; the following code takes 12ms:&lt;/p&gt;
&lt;p&gt;while (1) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; GPIO_debug_on(true); &lt;br /&gt;&amp;nbsp; &amp;nbsp; if (!nrfx_twim_is_busy(&amp;amp;m_twim))&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;break;&lt;br /&gt;&amp;nbsp; &amp;nbsp;GPIO_debug_on(false);&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;All the GPIO_debug_on does is toggle a gpio pin attached to a cathode ray oscilloscope. The switching of the gpio pin allows measurement of the time taken.&lt;/p&gt;
&lt;p&gt;Cheers Paul&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF_TWIM_IS_BUSY is taking up to 12ms to return</title><link>https://devzone.nordicsemi.com/thread/184301?ContentTypeID=1</link><pubDate>Mon, 29 Apr 2019 12:13:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:02576a69-430b-4c94-ab16-ceddd7146588</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I am not able to see from the question where the unexpected delay is. Can you clarify? Is it some function that returns&amp;nbsp;NRF_TWIM_IS_BUSY, but waits for too long before returning it? Which function? Or something else?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>