<?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>nRF51 and MPU6050 TWI Issue</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/11673/nrf51-and-mpu6050-twi-issue</link><description>Hi, 
 I&amp;#39;ve looked at the example codes provided by Martin in these two topics for communicating to a MPU6050 through TWI: 
 1- devzone.nordicsemi.com/.../ (uses SDK 9)
2- devzone.nordicsemi.com/.../ (uses SDK 10) 
 Just for others to know: The first</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 11 Mar 2016 04:10:34 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/11673/nrf51-and-mpu6050-twi-issue" /><item><title>RE: nRF51 and MPU6050 TWI Issue</title><link>https://devzone.nordicsemi.com/thread/44131?ContentTypeID=1</link><pubDate>Fri, 11 Mar 2016 04:10:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9d1b42b5-e536-41a7-acc1-4a4748e6fb8a</guid><dc:creator>FA</dc:creator><description>&lt;p&gt;I think &lt;a href="https://devzone.nordicsemi.com/question/68272/not-exiting-while-loop-after-a-twi-event/"&gt;this post&lt;/a&gt; was the reason of the unwanted delay discussed in the comments.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51 and MPU6050 TWI Issue</title><link>https://devzone.nordicsemi.com/thread/44130?ContentTypeID=1</link><pubDate>Wed, 17 Feb 2016 11:50:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9220632e-ae30-4866-bb58-2746e99fc5ae</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Just thought I should let you know that we will look into this, but the SDK team is very busy these days and it might take while.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51 and MPU6050 TWI Issue</title><link>https://devzone.nordicsemi.com/thread/44129?ContentTypeID=1</link><pubDate>Mon, 08 Feb 2016 05:55:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:784c4f1e-9c5d-425c-9cae-a07b7acb8a98</guid><dc:creator>FA</dc:creator><description>&lt;p&gt;I added another IO pin toggle after the while loop to see when the program comes out of it + a conditional IO toggle based on twi_tx_done:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;if (twi_tx_done) nrf_gpio_pin_toggle(20);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As shown in 3rd figure, this test again shows that there is a delay between the time the program goes to the TWI event handler and exiting the while loop. I don&amp;#39;t know what is causing this delay. The radio is not advertising when using TWI, and the previous scanning with time slot API has been closed by using:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;sd_radio_session_close ();
sd_nvic_DisableIRQ(SWI0_IRQn);
sd_nvic_DisableIRQ(SD_EVT_IRQn);
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51 and MPU6050 TWI Issue</title><link>https://devzone.nordicsemi.com/thread/44128?ContentTypeID=1</link><pubDate>Fri, 05 Feb 2016 04:12:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b9d7163c-d94c-498a-bd7a-27a394d7f210</guid><dc:creator>FA</dc:creator><description>&lt;p&gt;I updated the second figure with a new test. In this case an IO pin toggles after each NRF_DRV_TWI_RX_DONE event (in the TWI even handler). This should take the program out of the &lt;em&gt;while loop&lt;/em&gt; below and go to the next transmission. But as you can see there is a considerable delay between this signal and the next SCL changes.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;while((!twi_tx_done) &amp;amp;&amp;amp; timeout--);  
if(!timeout) return NRF_ERROR_TIMEOUT;
twi_tx_done = false;

err_code = nrf_drv_twi_tx(m_twi_instance, MPU9150_ADDRESS, p_data, length, false);
if(err_code != NRF_SUCCESS) return err_code;
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51 and MPU6050 TWI Issue</title><link>https://devzone.nordicsemi.com/thread/44127?ContentTypeID=1</link><pubDate>Thu, 04 Feb 2016 05:56:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5ce6eeac-aeda-4a8f-b342-9b9e8db63e10</guid><dc:creator>FA</dc:creator><description>&lt;p&gt;Hi again! In your trace we should look at the gap around 0.6msec, which is between writing address (0x19) and writing the first byte (0x07). Still the delay is around 50usec. I started playing with MPU9150_TWI_TIMEOUT, which was 5000 in previous code and is 4000+1 in the new code you posted here. To me this just looked like a maximum wait time to generate an error in I2C read/write functions. But as you can see in the 2nd trace when I changed it to 1000, the delay dropped to around 250usec. I was getting some TWI errors when I used 500 and will test it again. Any thoughts why is this happening? I&amp;#39;m attaching the main function and MPU files. Main is using the same functions you are using and I checked all the used functions in MPU files and they are the same as yours. My whole project files are not still well documented, so it might be confusing to post, but that might be our last resort.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51 and MPU6050 TWI Issue</title><link>https://devzone.nordicsemi.com/thread/44126?ContentTypeID=1</link><pubDate>Wed, 03 Feb 2016 15:08:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2737d421-78f6-48cd-a88e-aa7d38f27048</guid><dc:creator>FA</dc:creator><description>&lt;p&gt;Only in case of an error, yes, an LED blinks for 3 sec.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void mpu9150_twi_event_handler(const nrf_drv_twi_evt_t *evt)
{ 
    switch(evt-&amp;gt;type)
    {
        case NRF_DRV_TWI_TX_DONE:
            twi_tx_done = true;
            nrf_gpio_pin_toggle(0);
            break;
        case NRF_DRV_TWI_RX_DONE:
						 twi_rx_done = true;
						 nrf_gpio_pin_toggle(20);
            break;
        case NRF_DRV_TWI_ERROR:
						for(uint8_t i=1; i&amp;lt;4; i++) {
							 gpio_blink2(1000);
							 }
            switch(evt-&amp;gt;error_src)
            {
                case NRF_TWI_ERROR_ADDRESS_NACK:
                    break;
                case NRF_TWI_ERROR_OVERRUN_NACK:
                    break;
                case NRF_TWI_ERROR_DATA_NACK:
                    break;
                default:
                    break;
            }
            break;
        default:
            break;
    }        
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51 and MPU6050 TWI Issue</title><link>https://devzone.nordicsemi.com/thread/44125?ContentTypeID=1</link><pubDate>Wed, 03 Feb 2016 14:52:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c87e618b-878a-45e8-9b99-542458ff5801</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;I&amp;#39;m not seeing such delays. Here is my trace of the transmissions happening in mpu9150_config():
&lt;img src="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/logic.png" alt="image description" /&gt;&lt;/p&gt;
&lt;p&gt;As you can see there is only a 28.93us delay. Do you do anything in your TWI handler that might take time?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51 and MPU6050 TWI Issue</title><link>https://devzone.nordicsemi.com/thread/44124?ContentTypeID=1</link><pubDate>Wed, 03 Feb 2016 05:27:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b5cbfb42-2fbf-492a-a4e4-ce720919ca60</guid><dc:creator>FA</dc:creator><description>&lt;p&gt;Hi Martin, thanks for your response and the example in SDK 9. I figured out the problem was maybe due to the 10usec toggling code in the twi_tx_done + setting the oscilloscope to capture the few transitions. So, now I can see that the code goes to twi_tx_done and SCL/SDA pins are changing as shown in the attached picture. I have one other question about the timing of TWI events in this code, which maybe is good to have it answered in this topic: You can see a constant separation between TWI events, e.g., the above picture shows 4 writes to 4 different registers in the MPU and there is around 1.3msec between them. I saw a similar separation during twi_read between sending the register address and receiving its value. Is this something related to the nRF TWI driver or MPU? Which parameter controls it?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51 and MPU6050 TWI Issue</title><link>https://devzone.nordicsemi.com/thread/44123?ContentTypeID=1</link><pubDate>Tue, 02 Feb 2016 10:39:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:816df777-3114-4b6b-b083-5348cad4793d</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I ported the github MPU9150 example to SDK 9 (quick and dirty, but at least it works on my MPU9150). &lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/mpu9150_2D00_SDK_2D00_9.0.0.zip"&gt;Here is the ported example&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;A few questions:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Are you able to run the simple TWI example (without the MPU drivers) and get a response from your MPU? I.e. can you confirm that the MPU is working? If I understand you correctly you are able to communicate with it, but I still have to ask; are you using the correct pins?&lt;/li&gt;
&lt;li&gt;How are you monitoring the TWI pins? Do you have a logic trace so you are absolutely sure that nothing happens on the TWI lines?&lt;/li&gt;
&lt;li&gt;Maybe you can post your code? You can do it on our &lt;a href="https://www.nordicsemi.com/eng/Support-Community/Contact-Support-Team"&gt;Support Portal&lt;/a&gt; if you want some confidentiality.&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>