<?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 Event Handler Bypassing RX Transfer</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/35915/twi-event-handler-bypassing-rx-transfer</link><description>I am in the initial phases of porting an arduino project using the NRF52832 to the Nordic SDK (14.2 for the moment) and am running into issues when using TWIM and an event handler. This stage of my port effort is based on the twi_sensor example and I</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 02 Jul 2018 08:31:55 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/35915/twi-event-handler-bypassing-rx-transfer" /><item><title>RE: TWI Event Handler Bypassing RX Transfer</title><link>https://devzone.nordicsemi.com/thread/138456?ContentTypeID=1</link><pubDate>Mon, 02 Jul 2018 08:31:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:25e93ca5-740e-4469-b78d-6255823f2ba2</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Your assumption regarding where to put the wait (for non-blocking operation) is correct.&lt;/p&gt;
&lt;p&gt;If you do not want the module to use any global&amp;#39;s, an alternative is to keep the tx/rx logic in main, or to pass the m_xfer_rx_done to the function, but this adds complexity on how to use the module. If you want the module to be able to handle both blocking and non-blocking TWI transactions, the complexity will grow.&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: TWI Event Handler Bypassing RX Transfer</title><link>https://devzone.nordicsemi.com/thread/138349?ContentTypeID=1</link><pubDate>Fri, 29 Jun 2018 18:46:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:826c0039-28c1-4ff1-b4d0-d901eb83008f</guid><dc:creator>Patrick</dc:creator><description>&lt;p&gt;H&amp;aring;kon,&lt;/p&gt;
&lt;p&gt;Thank you for taking a look. If I could get some clarification on your suggestion of adding a wait to the readReg function. I assume that I need to add the below (directly before the _rx call) to not add a blocking loop to my function while waiting for the callback function to complete. Is this what you had in mind?&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;do
{
	__WFE();
} while (m_xfer_rx_done == false);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;By adding the above I will also need to maintain a local m_xfer_rx_done variable inside of my sensor library and set it accordingly from twi_handler() and any other related function. I think what I have described will work, as long as the obvious pitfall of keeping m_xfer_rx_done synced between my library and main is kept in check.&lt;/p&gt;
&lt;p&gt;All of this has me questioning if my design decision to have the TWI instance reference passed into the sensor library and letting main.c manage TWI, as opposed to configuring and handling TWI within the library was a smart move. My rationale was that once I add other devices to the bus I did not want to have multiple libraries trying to manage a TWI instance, just do it in one place, main. This is a little off topic I&amp;#39;m sure and more of a design question but if you have any thoughts on this design I&amp;#39;d like to hear them.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks again,&lt;br /&gt;Patrick&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI Event Handler Bypassing RX Transfer</title><link>https://devzone.nordicsemi.com/thread/138232?ContentTypeID=1</link><pubDate>Fri, 29 Jun 2018 09:07:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b6de11ad-3d4d-4351-bb87-489797129cc0</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 the ::readReg() function, you are not waiting for the callback main.c::twi_handler() to finish processing the first call to nrf_drv_twi_tx, which makes the next call to nrf_drv_twi_rx fail.&lt;/p&gt;
&lt;p&gt;I&amp;#39;d recommend that you check the error code for the _rx call as well.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you try to add a wait in the ::readReg() function and see if this works?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best 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>