<?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>Sequential calls to nrf_drv_twi_tx fails [SDK9]</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/10109/sequential-calls-to-nrf_drv_twi_tx-fails-sdk9</link><description>When calling nrf_drv_twi_tx() once like in the snippet below it works, but when the function is called two or more times sequentially, it fails. However running a nrf_delay_ms() delay between the calls makes it work again. 
 Works 
 nrf_drv_twi_init</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sun, 30 Sep 2018 15:58:35 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/10109/sequential-calls-to-nrf_drv_twi_tx-fails-sdk9" /><item><title>RE: Sequential calls to nrf_drv_twi_tx fails [SDK9]</title><link>https://devzone.nordicsemi.com/thread/150869?ContentTypeID=1</link><pubDate>Sun, 30 Sep 2018 15:58:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fbe33b67-142c-48a6-8caf-2574a462f53b</guid><dc:creator>Humberto Matias Cosentini</dc:creator><description>&lt;p&gt;Hey you didn&amp;#39;t create a new question... did you solve the problem? I believe I&amp;#39;m having a similar issue&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sequential calls to nrf_drv_twi_tx fails [SDK9]</title><link>https://devzone.nordicsemi.com/thread/148083?ContentTypeID=1</link><pubDate>Mon, 10 Sep 2018 16:21:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e2b72b77-bb09-411f-8f8e-479a537edc09</guid><dc:creator>Siraj</dc:creator><description>&lt;p&gt;No problem. Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sequential calls to nrf_drv_twi_tx fails [SDK9]</title><link>https://devzone.nordicsemi.com/thread/147959?ContentTypeID=1</link><pubDate>Mon, 10 Sep 2018 09:10:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:72a80ce2-34a5-4b16-8340-6297f09c5c4d</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi &lt;span&gt;Siraj&lt;/span&gt;,&lt;/p&gt;
&lt;p&gt;Please create a new question as this is not directly related to the original thread.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sequential calls to nrf_drv_twi_tx fails [SDK9]</title><link>https://devzone.nordicsemi.com/thread/147906?ContentTypeID=1</link><pubDate>Sun, 09 Sep 2018 20:40:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:09a13210-86d7-45e3-b8a6-b4c59b521312</guid><dc:creator>Siraj</dc:creator><description>&lt;p&gt;Hi Einar! I am trying to implement your callback procedure for a sequential transaction purposes, I want to be able to send another read request as soon as the first transaction is done. First I tried the blocking mode but that is&amp;nbsp;causing an internal error (Code 3). I put a time delay between transactions, and that keeps the data flowing for some time. Now, I am connecting the nRF52480 kit with the sensor board using wires (jumper wires). I know this is not the best practise but it&amp;#39;s alright for prototyping purposes. I then tried the non-blocking mode, where a handler sets a flag to true once the Done event is received. I check for the flag in a while loop. However, more often than not, I get stuck in the while loop. The handler callback doesn&amp;#39;t get called and the flag is not set. I think it&amp;#39;s analogous to error code 3 I received in the blocking mode and therefore, the same cause (long wires and noise). But I just want to make sure it is what I think since I couldn&amp;#39;t find or trace how the handler function is called back.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Siraj&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sequential calls to nrf_drv_twi_tx fails [SDK9]</title><link>https://devzone.nordicsemi.com/thread/37489?ContentTypeID=1</link><pubDate>Fri, 06 Nov 2015 14:54:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a9c314f5-4c89-4597-9bd1-af2ff9b5b620</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;You are right. Good to hear you fond he problem.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sequential calls to nrf_drv_twi_tx fails [SDK9]</title><link>https://devzone.nordicsemi.com/thread/37488?ContentTypeID=1</link><pubDate>Fri, 06 Nov 2015 14:53:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ffce4526-fd83-40a9-b993-f7bd728dccc0</guid><dc:creator>robertfoss</dc:creator><description>&lt;p&gt;&lt;code&gt;nrf_drv_twi_tx()&lt;/code&gt; will not return immediately when run in blocking mode, which is is (as stated in &lt;code&gt;nrf_drv_twi_init(&amp;amp;twi, NULL, NULL);&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;However I found the issue. The flash IC I am using requires a 10ms backoff between write cycles.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sequential calls to nrf_drv_twi_tx fails [SDK9]</title><link>https://devzone.nordicsemi.com/thread/37487?ContentTypeID=1</link><pubDate>Fri, 06 Nov 2015 09:49:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6cc51650-74fd-4e79-9c27-1d6e5373d87f</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;The &lt;code&gt;nrf_drv_twi_tx()&lt;/code&gt; will always return immediately. The first call will likely return &lt;code&gt;NRF_SUCCESS&lt;/code&gt;. Then should normally not make new call to &lt;code&gt;nrf_drv_twi_tx()&lt;/code&gt; until you get a callback in the event handler &lt;code&gt;nrf_drv_twi_init()&lt;/code&gt;. (As you have not supplied any event handler you will not get this event.)&lt;/p&gt;
&lt;p&gt;When you make the second call to &lt;code&gt;nrf_drv_twi_tx()&lt;/code&gt; immediately after the first call, the transfer is not completed, and the second call will likely return &lt;code&gt;NRF_ERROR_BUSY&lt;/code&gt;. You do not check the return value, so you are in the blind here as well.&lt;/p&gt;
&lt;p&gt;Your work around, waiting for some time, should work most of the time. However you do not know if you are waiting long enough or you may be waiting for far longer than you have to. Moreover there is no way to be confident that the transfer was successful as long as you do not check the callback events.&lt;/p&gt;
&lt;p&gt;So to fix this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Implement the event handler and provide a pointer to it in your call to &lt;code&gt;nrf_drv_twi_init()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Check the return value of calls to &lt;code&gt;nrf_drv_twi_tx()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Do not make a new call to &lt;code&gt;nrf_drv_twi_tx()&lt;/code&gt; until you have received an event reporting the result of the previous call&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;See the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk51.v9.0.0/group__nrf__twi__drv.html?cp=4_1_0_6_6_21_1"&gt;TWI driver documentation&lt;/a&gt; for details.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>