<?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>Blocking &amp;amp; Non-Blocking operations on TWI</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/48249/blocking-non-blocking-operations-on-twi</link><description>Hello, 
 
 I am using nRF52832, SDK_15.3.0, S132 SoftDevice and Segger for flashing the image. I am using ‘ble_app_blinky’. 
 
 I connected my sensor to nRF52832 DK over TWI. When ‘twi_scanner’ example code loaded I received the address of the slave device</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 06 Jun 2019 09:20:49 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/48249/blocking-non-blocking-operations-on-twi" /><item><title>RE: Blocking &amp; Non-Blocking operations on TWI</title><link>https://devzone.nordicsemi.com/thread/191279?ContentTypeID=1</link><pubDate>Thu, 06 Jun 2019 09:20:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:66d21763-e277-4436-a214-3383416321c3</guid><dc:creator>beemavishnu</dc:creator><description>&lt;p&gt;Thank you for your confirmation&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Blocking &amp; Non-Blocking operations on TWI</title><link>https://devzone.nordicsemi.com/thread/191278?ContentTypeID=1</link><pubDate>Thu, 06 Jun 2019 09:00:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f4ebc99b-e8bf-4523-b8fd-aa9fd82381df</guid><dc:creator>&amp;#216;yvind</dc:creator><description>[quote user="beemavishnu"]Yes, in ble_app_blinky, I mixed both &amp;#39;twi_scanner&amp;#39; to read the address and &amp;#39;twi_sensor&amp;#39; to add twi handler.[/quote]
&lt;p&gt;&amp;nbsp;Ok, thanks!&amp;nbsp;&lt;/p&gt;
[quote user="beemavishnu"]If &amp;#39;twi_scanner&amp;#39; example is blocking mode, then can I assume &amp;#39;twi_sensor&amp;#39; as non-blocking mode. But still due to &amp;#39;while (m_xfer_done == false)&amp;#39; whether &amp;#39;twi_sensor&amp;#39; code will behave as a blocking mode. Please correct me if I am wrong.[/quote]
&lt;p&gt;&amp;nbsp;TWI_sensor is considered as a non-blocking example since it uses a twi_handler, at least the twi driver is configured as non-blocking. However, I agree that the example is confusing when adding the flag &lt;em&gt;m_xfer_done&lt;/em&gt;,&amp;nbsp;when polling this flag the example could potentially be blocking.&lt;/p&gt;
&lt;p&gt;Hope this clears some confusion.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Kind regards,&lt;br /&gt;Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Blocking &amp; Non-Blocking operations on TWI</title><link>https://devzone.nordicsemi.com/thread/191277?ContentTypeID=1</link><pubDate>Wed, 05 Jun 2019 13:24:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f405e6b0-815b-4eb7-ab25-22926ff730a7</guid><dc:creator>beemavishnu</dc:creator><description>&lt;p&gt;Yes, in ble_app_blinky, I mixed both &amp;#39;twi_scanner&amp;#39; to read the address and &amp;#39;twi_sensor&amp;#39; to add twi handler.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Blocking &amp; Non-Blocking operations on TWI</title><link>https://devzone.nordicsemi.com/thread/191276?ContentTypeID=1</link><pubDate>Wed, 05 Jun 2019 13:20:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:05aaba86-975c-42f3-a3b6-1f5a9ed485a3</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Just to clarify, as I just realized you wrote &amp;quot;&lt;span&gt;&amp;nbsp;&lt;em&gt;I have gone through ‘twi_senor’ example&amp;nbsp;&lt;/em&gt;&amp;quot;:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;You have ported the twi_scanner example into ble_blinky and configured this as the twi_sensor example including the twi_handler?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Blocking &amp; Non-Blocking operations on TWI</title><link>https://devzone.nordicsemi.com/thread/191275?ContentTypeID=1</link><pubDate>Wed, 05 Jun 2019 13:20:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:538c75f0-01d1-44af-b043-507d1fa511e6</guid><dc:creator>beemavishnu</dc:creator><description>&lt;p&gt;Thank you for your inputs.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;1)&amp;nbsp; twi_handler() is same as in &amp;#39;twi_sensor&amp;#39; example.&lt;/p&gt;
&lt;p&gt;2) If &amp;#39;twi_scanner&amp;#39; example is blocking mode, then can I assume &amp;#39;twi_sensor&amp;#39; as non-blocking mode. But still due to &amp;#39;while (m_xfer_done == false)&amp;#39; whether &amp;#39;twi_sensor&amp;#39; code will behave as a blocking mode. Please correct me if I am wrong.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks &amp;amp; Regards&lt;/p&gt;
&lt;p&gt;Vishnu Beema&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Blocking &amp; Non-Blocking operations on TWI</title><link>https://devzone.nordicsemi.com/thread/191274?ContentTypeID=1</link><pubDate>Wed, 05 Jun 2019 13:11:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bbadb7fe-0e61-42b9-b3f0-0b5e7ce254a9</guid><dc:creator>&amp;#216;yvind</dc:creator><description>[quote user=""]When ‘twi_handler’ added, I get success for all 127 address. I am not sure why this happened.[/quote]
&lt;p&gt;&amp;nbsp;What does&amp;nbsp;your twi_handler function look like?&amp;nbsp;&lt;/p&gt;
[quote user=""]Under ‘&lt;strong&gt;nrf_drv_twi_init&lt;/strong&gt;’ for event handler it is mentioned as “If NULL, blocking mode is enabled”. What does it mean[/quote]
&lt;p&gt;&amp;quot;&lt;em&gt;Blocking communication means that the MCU stalls until the byte is transferred from the data register. In the code, this is usually implemented as checking of the status bit in the “while” loop. However, this approach might not be applicable for some time-critical applications&lt;/em&gt;&amp;quot;&lt;br /&gt;&lt;br /&gt;The TWI Scanner uses blocking mode. To enable non-blocking mode, you can add a twi_handler.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Please see the &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.3.0/hardware_driver_twi.html?resultof=%22%6e%72%66%5f%64%72%76%5f%74%77%69%5f%69%6e%69%74%22%20"&gt;TWI master documentation&lt;/a&gt; on basic usage.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>