<?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>How to read multiple sensors over TWI? (nrf_drv_twi)</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/10702/how-to-read-multiple-sensors-over-twi-nrf_drv_twi</link><description>I had slightly modified a TWI example (using nrf_drv_twi) to work with one of my sensors; It&amp;#39;s basically the same with a different function called to handle the received data. 
 However, I have multiple sensors and multiple sets of data I&amp;#39;d like to be</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 09 Dec 2015 10:39:26 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/10702/how-to-read-multiple-sensors-over-twi-nrf_drv_twi" /><item><title>RE: How to read multiple sensors over TWI? (nrf_drv_twi)</title><link>https://devzone.nordicsemi.com/thread/39953?ContentTypeID=1</link><pubDate>Wed, 09 Dec 2015 10:39:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0ea58a24-1fb8-44b1-8511-9c9042a3c9ec</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;I don&amp;#39;t have the full overview of the new app_twi module, but it looks like it does exactly what you need.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to read multiple sensors over TWI? (nrf_drv_twi)</title><link>https://devzone.nordicsemi.com/thread/39952?ContentTypeID=1</link><pubDate>Tue, 08 Dec 2015 16:03:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bb39bc24-a813-4bd8-9e27-b7ae20579fb5</guid><dc:creator>Sensors</dc:creator><description>&lt;p&gt;This seemed a little hack-y to me so didn&amp;#39;t want to do it that way unless there was no other way. It seems like it&amp;#39;ll get very messy however if I have multiple sensors with varying lengths of data to be received.&lt;/p&gt;
&lt;p&gt;I haven&amp;#39;t looked into it, but would the app_twi abstraction layer work better in my situation?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to read multiple sensors over TWI? (nrf_drv_twi)</title><link>https://devzone.nordicsemi.com/thread/39951?ContentTypeID=1</link><pubDate>Tue, 08 Dec 2015 13:36:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:08c2ba8c-2e1c-482c-bab3-012797ee12a2</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;&lt;code&gt;nrf_drv_twi_tx(...)&lt;/code&gt; will always be followed by an &lt;code&gt;NRF_DRV_TWI_TX_DONE&lt;/code&gt; event and &lt;code&gt;nrf_drv_twi_rx(...)&lt;/code&gt; will always be followed by an &lt;code&gt;NRF_DRV_TWI_RX_DONE&lt;/code&gt; event. Between the function call and the event, no other transactions will be allowed, meaning &lt;code&gt;nrf_drv_twi_tx(...)&lt;/code&gt; or &lt;code&gt;nrf_drv_twi_rx(...)&lt;/code&gt; will return &lt;code&gt;NRF_ERROR_BUSY&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You will need to handle the multiple sensors in your code. You can set a flag when starting transfer to the sensor and then check it in the TX or RX done events to know what action to do, something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;err_code = nrf_drv_twi_tx(...);
APP_ERROR_CHECK(err_code);    //you may want to do something else if NRF_ERROR_BUSY
m_sensor1_xfer_started = true;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And in the &lt;code&gt;NRF_DRV_TWI_TX_DONE&lt;/code&gt; event do something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;if(m_sensor1_xfer_started)
{
    m_sensor1_xfer_started = false;
    //code for sensor 1 tx done
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>