<?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 handler with nrf_drv_twi_tx()</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/14341/twi-handler-with-nrf_drv_twi_tx</link><description>I have created a library for HD44780 Hitachi LCD, and I can transmit data to the LCD through an IO Expander without any problem over TWI lines. Right now I am not using any TWI Handler function for transmitting data. 
 I have functions within lcd_init</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 09 Jun 2016 09:27:34 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/14341/twi-handler-with-nrf_drv_twi_tx" /><item><title>RE: TWI handler with nrf_drv_twi_tx()</title><link>https://devzone.nordicsemi.com/thread/54768?ContentTypeID=1</link><pubDate>Thu, 09 Jun 2016 09:27:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:292e8608-cb57-47b7-80df-2e6f96f6109c</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Yes, that is right. If you haven&amp;#39;t done so already you can take a look at the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v11.0.0/twi_sensor_example.html?cp=5_0_0_4_5_28"&gt;twi_sensor example in the SDK&lt;/a&gt;. It does exactly as you suggest. You can also see that they start the TX in the main while(true) loop and then start the RX from within the twi_handler() to read data from the sensor.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI handler with nrf_drv_twi_tx()</title><link>https://devzone.nordicsemi.com/thread/54767?ContentTypeID=1</link><pubDate>Wed, 08 Jun 2016 18:16:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:69e05135-e57d-4431-a701-a0b9c9709331</guid><dc:creator>Mark</dc:creator><description>&lt;p&gt;Hi Martin,&lt;/p&gt;
&lt;p&gt;Thanks for your great explanation.&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t really care about current consumption, but just wanted to learn how create a proper &lt;code&gt;twi_handler()&lt;/code&gt; function. Later on, I will add a RFID Card Reader device on the same TWI line along with this LCD.&lt;/p&gt;
&lt;p&gt;I tried the &lt;code&gt;twi_handler()&lt;/code&gt; function above and worked like you said. But as you pointed out if I just wait for the transfer to complete in a while() loop I lose the benefit of using a handler. So, how should I change my code to take advantage of &lt;code&gt;twi_handler()&lt;/code&gt; function?&lt;/p&gt;
&lt;p&gt;Do I have to use the a condition similar to this piece of code to take advantage of &lt;code&gt;twi_handler()&lt;/code&gt; function, or not necessarily?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;   `do
    {
        __WFE();
    }while(xfer_completed == false);
    nrf_drv_twi_tx(&amp;amp;m_twi_hd44780, LCD_addr, &amp;amp;buffer, sizeof(buffer), false);
    xfer_completed = false;`
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI handler with nrf_drv_twi_tx()</title><link>https://devzone.nordicsemi.com/thread/54766?ContentTypeID=1</link><pubDate>Wed, 08 Jun 2016 13:32:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4b9de603-7ab0-4281-bf0b-1256cbd36da3</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;No, you don&amp;#39;t really need it if you don&amp;#39;t care about current consumption or the fact that without a handler nrf_drv_twi_tx() will block the CPU from performing other tasks during the TWI transfer. If you use a handler you can save power by entering sleep mode while the TWI is doing its thing. Or you can let the CPU work on other tasks and get more stuff done faster.&lt;/p&gt;
&lt;p&gt;Your code should work. However, if you just wait for the transfer to complete in a while() loop you lose the benefit of using a handler. Your CPU will continuously check whether &lt;code&gt;xfer_completed&lt;/code&gt; is true or false unable to work on other things and consuming power.&lt;/p&gt;
&lt;p&gt;By using &lt;code&gt;xfer_pending&lt;/code&gt; you can tell the driver that you want to generate a stop condition after a transfer. If you issue a stop condition after a transfer it indicates to all devices on the TWI bus that you are done with all transfers and that the bus is free to use. If you don&amp;#39;t issue a stop condition it means that you, as the TWI master, want to keep control of the bus because you expect to send more data. So as long as you are only communicating with one slave I don&amp;#39;t think it matters if you use &lt;code&gt;xfer_pending&lt;/code&gt; or not.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>