<?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>nRF52 failed to read from max30102 through I2C</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/18974/nrf52-failed-to-read-from-max30102-through-i2c</link><description>I&amp;#39;ve been trying to use nRF52 (PCA10040 board) with SDK 12 to read data from max30102 through I2C. 
 I used non-blocking read and this is twi init function and event hander: 
 void twi_init (void)
{
 ret_code_t err_code;

 const nrf_drv_twi_config_t</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 23 Jan 2017 13:54:16 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/18974/nrf52-failed-to-read-from-max30102-through-i2c" /><item><title>RE: nRF52 failed to read from max30102 through I2C</title><link>https://devzone.nordicsemi.com/thread/73335?ContentTypeID=1</link><pubDate>Mon, 23 Jan 2017 13:54:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c8e3fd7f-a01c-421e-87d3-06ec138d7af1</guid><dc:creator>Petter Myhre</dc:creator><description>&lt;p&gt;Yes, you should wait for m_xfer_done to be true before you start a new transfer. I wouldn&amp;#39;t use a while, I would check the flag in the main loop and start the next transfer from there. Or maybe you can just use the driver in blocking mode?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52 failed to read from max30102 through I2C</title><link>https://devzone.nordicsemi.com/thread/73334?ContentTypeID=1</link><pubDate>Mon, 16 Jan 2017 00:07:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:048edd20-f596-4653-9dcd-3f54c9c15bb3</guid><dc:creator>djqtsg</dc:creator><description>&lt;p&gt;Now I know where is the problem is:&lt;/p&gt;
&lt;p&gt;After calling nrf_drv_twi_tx(), I should wait for twi_handler() being called and m_xfer_done changed to true.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;err_code = nrf_drv_twi_tx(&amp;amp;twi_instance, device_address, &amp;amp;reg_addr, 1, true);

while(!m_xfer_done);

err_code = nrf_drv_twi_rx(&amp;amp;twi_instance, device_address, part_id, 1);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now my question would be:&lt;/p&gt;
&lt;p&gt;Is it safe to add while(!m_xfer_done)? What if in twi_handler() events other than TWI_EVT_DONE happens, and m_xfer_done is not changed to true, that while statement loops forever, isn&amp;#39;t it?&lt;/p&gt;
&lt;p&gt;How about I use nrf_delay_us(10) instead of while(!m_xfer_done);&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52 failed to read from max30102 through I2C</title><link>https://devzone.nordicsemi.com/thread/73333?ContentTypeID=1</link><pubDate>Fri, 13 Jan 2017 10:03:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cd925b2c-9da8-4285-94fb-482d1b1783a7</guid><dc:creator>Petter Myhre</dc:creator><description>&lt;p&gt;Is nrf_drv_twi_rx() always returning 0x11? This means NRF_ERROR_BUSY - If the driver is not ready for a new transfer.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>