<?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 Troubles With nRF51 DK and MMA8452 Accelerometer</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/18384/twi-troubles-with-nrf51-dk-and-mma8452-accelerometer</link><description>I have an accelerometer that utilizes IC2 (NXP MMA8452Q) that I am trying to integrate with the nRF51 DK. The accelerometer is on a breakout board, and is wired up very simply using the SCL, SDA, and the power supply pins. I am basing the implementation</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 16 Dec 2016 08:02:33 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/18384/twi-troubles-with-nrf51-dk-and-mma8452-accelerometer" /><item><title>RE: TWI Troubles With nRF51 DK and MMA8452 Accelerometer</title><link>https://devzone.nordicsemi.com/thread/70968?ContentTypeID=1</link><pubDate>Fri, 16 Dec 2016 08:02:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e0911b1b-48cf-4751-9f7c-a2544cfe58ea</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;Glad to hear that you found the cause of the issue!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI Troubles With nRF51 DK and MMA8452 Accelerometer</title><link>https://devzone.nordicsemi.com/thread/70967?ContentTypeID=1</link><pubDate>Thu, 15 Dec 2016 17:30:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4f7dabeb-92ae-4291-a8c4-72422bab314c</guid><dc:creator>eeboarder</dc:creator><description>&lt;p&gt;I found the problem and got it working. In the nrf_drv_twi_tx call inside the data_read() function, I had the no_stop parameter set to false. When I set it to true, I was receiving the correct WHO_AM_I response.&lt;/p&gt;
&lt;p&gt;Below is the updated function for those who come across the same problem.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/**
 * @brief Function for reading data from the accelerometer.
 */
static void read_data()
{
		ret_code_t err_code;
		uint8_t addr8 = WHO_AM_I;
	
		printf(&amp;quot;WHO_AM_I Tx\r\n&amp;quot;);

        m_xfer_done = false;
		err_code = nrf_drv_twi_tx(&amp;amp;m_twi, MMA8452_ADDR, &amp;amp;addr8, 1, true);
		printf(&amp;quot;tx err_code is %d\r\n&amp;quot;, err_code);
		while (m_xfer_done == false);	

		printf(&amp;quot;WHO_AM_I Rx\r\n&amp;quot;);
	
		m_xfer_done = false;
		err_code = nrf_drv_twi_rx(&amp;amp;m_twi, MMA8452_ADDR, &amp;amp;m_sample, 1);
		APP_ERROR_CHECK(err_code);
		printf(&amp;quot;rx err_code is %d\r\n&amp;quot;, err_code);

		while (m_xfer_done == false);	
	
		printf(&amp;quot;read_data() done\r\n&amp;quot;);
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI Troubles With nRF51 DK and MMA8452 Accelerometer</title><link>https://devzone.nordicsemi.com/thread/70966?ContentTypeID=1</link><pubDate>Thu, 15 Dec 2016 17:12:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eabeff09-6f99-4612-8e4d-fccc9bfc561c</guid><dc:creator>eeboarder</dc:creator><description>&lt;p&gt;Bjorn, I added the (m_xfer_done == false); like you had mentioned. I also de-soldered the wires to the breakout board and rewired with hookup wires that go directly to the headers on the DK. It does seem more consistent now. No resets for stalls. Below is what I&amp;#39;m seeing over UART. I still do not appear to be getting my expected WHO_AM_I value, though.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Start TWI
TWI Initialized
wake errtwi_handler event.
NRF_DRV_TWI_EVT_DONE:
_code is 0
MMA8452 Setup and Wake Complete.
WHO_AM_I Tx
tx errtwi_handler event.
NRF_DRV_TWI_EVT_DONE:
_code is 0
WHO_AM_I Tx
rx errtwi_handler event.
NRF_DRV_TWI_EVT_DONWHO_AM_I Tx
tx errtwi_handler event.
NRF_DRV_TWI_EVT_DONE:
_code is 0
WHO_AM_I Tx
rtwi_handler event.
NRF_DRV_TWI_EVT_DONE:
Data Read: 0xff
x err_code is 0
read_data() done
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Repeating....&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI Troubles With nRF51 DK and MMA8452 Accelerometer</title><link>https://devzone.nordicsemi.com/thread/70964?ContentTypeID=1</link><pubDate>Thu, 15 Dec 2016 09:03:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d6772aaa-9a63-4103-a567-9ca3c70cea52</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;One thing I noticed is that you should add while (m_xfer_done == false); after the last nrf_drv_twi_rx() n read_data(). I do not think that this should matter since you have a 2second delay in the main loop, but better safe than sorry. Are the I2C lines on the  MMA8452Q break-out board properly grounded?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI Troubles With nRF51 DK and MMA8452 Accelerometer</title><link>https://devzone.nordicsemi.com/thread/70965?ContentTypeID=1</link><pubDate>Wed, 14 Dec 2016 19:05:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d481cad4-6901-43e9-9fe9-bacc70624fda</guid><dc:creator>eeboarder</dc:creator><description>&lt;p&gt;Bjorn, nrf_drv_twi_rx is returning &amp;quot;NRF_SUCCESS&amp;quot;.&lt;/p&gt;
&lt;p&gt;Here are the defines for the pins, which do line up with the SCL and SDA  pins on the nRF51 DK.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Arduino board mappings
#define ARDUINO_SCL_PIN             7     // SCL signal pin
#define ARDUINO_SDA_PIN             30    // SDA signal pin
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This morning, the same code appears to working with nrf_drv_twi_rx, but it is returning 0xff, not 0x2a, which is what it should be seeing.....&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI Troubles With nRF51 DK and MMA8452 Accelerometer</title><link>https://devzone.nordicsemi.com/thread/70963?ContentTypeID=1</link><pubDate>Wed, 14 Dec 2016 13:06:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1b584505-48cb-4e5d-82fd-e8d7ba6db1d9</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;Which error code does nrf_drv_twi_rx return? Have you verified that the ARDUINO_SCL_PIN and ARDUINO_SDA_PIN defines correspond to the pins you have connected to the MMA8452?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>