<?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>NRF51422 TWI not functioning properly</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/13517/nrf51422-twi-not-functioning-properly</link><description>Hello, i have a strange situation here with TWI module and i have no idea what is happening. I have read a lot of posts here on devzone and the code i am using is also found somewhere on this forum, however in none of the post i found the same behaviour</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 29 Apr 2016 11:37:42 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/13517/nrf51422-twi-not-functioning-properly" /><item><title>RE: NRF51422 TWI not functioning properly</title><link>https://devzone.nordicsemi.com/thread/51594?ContentTypeID=1</link><pubDate>Fri, 29 Apr 2016 11:37:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0dc12a2f-d4ad-4fa3-b26f-41ea80b6697b</guid><dc:creator>Artucas</dc:creator><description>&lt;p&gt;Thank you Kenneth, Regards.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF51422 TWI not functioning properly</title><link>https://devzone.nordicsemi.com/thread/51593?ContentTypeID=1</link><pubDate>Fri, 29 Apr 2016 10:37:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:32af481d-a649-4a3b-a686-947441139cc2</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Typically the twi instance used must be defined when calling nrf_drv_twi_init(), e.g. in the following way:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static const nrf_drv_twi_t m_twi_mma_7660 = NRF_DRV_TWI_INSTANCE(0);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You will also need to enable/modify the twi instance in nrf_drv_config.h&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF51422 TWI not functioning properly</title><link>https://devzone.nordicsemi.com/thread/51592?ContentTypeID=1</link><pubDate>Fri, 29 Apr 2016 10:24:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f9ef4fa1-acfb-45d7-9be8-b49e77fea69e</guid><dc:creator>Artucas</dc:creator><description>&lt;p&gt;Hello Keneth, thank you for your support. Your comments helped me to solve the problem. It was a timing problem. I missed that my sensor takes about 10ms to do a measurement conversion. Incredible how these obvious things can cause so much trouble.. Shows that still have to learn a lot and to think a lot about doing something new ;) I will update to newest SDK. However i want to ask one more thing. Right now am i missing something, or this TWI module written by nordic only uses TWI1? I don&amp;#39;t see a way to change it to TWI0. IS that possible? Thanks again Kenneth, Regards.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF51422 TWI not functioning properly</title><link>https://devzone.nordicsemi.com/thread/51591?ContentTypeID=1</link><pubDate>Fri, 29 Apr 2016 09:36:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b0eaaa13-819b-4478-b620-63a47cf3bb46</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;The first trace looks good, the sensor ACK the transacation and the data is written on the twi bus. The second trace the sensor NACK the transaction for unknown reason (maybe it&amp;#39;s not ready to receive data). The third trace show a small dip in supply voltage some time before the twi transacation, most likely some circuitry is drawing current, this is normal.&lt;/p&gt;
&lt;p&gt;My recommendation is to check that you are using an &lt;a href="https://www.nordicsemi.com/eng/nordic/download_resource/41917/8/74341562"&gt;nRF51 of 3rd revision&lt;/a&gt; and update to the latest nRF5 SDK if you haven&amp;#39;t already. If the sensor NACK, then add a small delay and retry. Make sure to set breakpoints after the complete transacation is finished (even if it fails), either by using blocking twi calls or use a flag from the event handler. This make it easier to see if the twi driver send the stop condition as expected after an NACK, and is ready for a new transfer.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF51422 TWI not functioning properly</title><link>https://devzone.nordicsemi.com/thread/51589?ContentTypeID=1</link><pubDate>Thu, 28 Apr 2016 13:46:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ee9a62ce-ec78-4912-a40a-3132b08ae8e6</guid><dc:creator>Artucas</dc:creator><description>&lt;p&gt;it does return NRF_DRV_TWI_ERROR. I dont find any information, but could it be that it takes some time to initialize TWI module, when used with soft device? because now i just randomly tried to add big delay after initializing twi module, and it started to work like expected. However i see something strange just few ms before communication starts. So do you know anything about this, can you confirm it? Please see mi initial question, i edited my question and added third picture to show what happened after adding delay like shown in code snippet below.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;nrf_drv_twi_enable(&amp;amp;p_twi_instance); // Enable the TWI instance
		const uint8_t dummy_data = 0xE3;
	  for(uint32_t i = 0; i &amp;lt; 50000; i++);
		ret_code = nrf_drv_twi_tx(&amp;amp;p_twi_instance, 0x80, &amp;amp;dummy_data, 1, false);
		APP_ERROR_CHECK(ret_code); // Check for errors in return value
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF51422 TWI not functioning properly</title><link>https://devzone.nordicsemi.com/thread/51588?ContentTypeID=1</link><pubDate>Thu, 28 Apr 2016 13:33:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c3cd194f-8824-4b98-987c-9bfe52297500</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;In any case I suggest to try the twi example in the latest SDK, there have been improvements and fixes to the driver that might apply. Check out the latest nRF5 SDK v11 (or later) and go to \examples\peripheral\twi_sensor&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF51422 TWI not functioning properly</title><link>https://devzone.nordicsemi.com/thread/51587?ContentTypeID=1</link><pubDate>Thu, 28 Apr 2016 13:28:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ca2e6803-357e-44e8-8878-c8fadc15d71c</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Doesn&amp;#39;t the twi_event_handler() execute at all, or does it return a different event than NRF_DRV_TWI_TX_DONE?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF51422 TWI not functioning properly</title><link>https://devzone.nordicsemi.com/thread/51590?ContentTypeID=1</link><pubDate>Thu, 28 Apr 2016 12:59:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:29e2c8df-1e67-4722-82ab-aaaf365e333a</guid><dc:creator>Artucas</dc:creator><description>&lt;p&gt;Hello Kenneth, thank you for your answer. I get your point now. However, i tried to do as you recommended and put a break point in twi_event_handler, code below.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void twi_event_handler(nrf_drv_twi_evt_t *evt){
     
    if(evt-&amp;gt;type == NRF_DRV_TWI_TX_DONE)
    {
			twi_event_flag = 1;
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;However, the code never gets hear (i never get to the part of the code which sets twi_event_flag t o1), so it looks like the callback is never called? And i still see the same thing with oscilloscope as in the second oscillogram as in my initial question. If i pass NULL to nrf_drv_twi_init() instead of twi_handler, i still see the same with oscilloscope. I tried to use different pins for this, but still i am getting the same result. Do you have any idea what else could be the problem?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF51422 TWI not functioning properly</title><link>https://devzone.nordicsemi.com/thread/51586?ContentTypeID=1</link><pubDate>Thu, 28 Apr 2016 11:08:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:56721bd4-b8f6-4995-9fad-330732cc24d8</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hi, I am not sure which version of the twi driver you are using, but I can see from the init function that it&amp;#39;s before nRF5 SDK v11. In general it&amp;#39;s a good idea to update to the latest when there are SDK updates.&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t actually see any specific error or question here, and the traces looks reasonable. The nrf_drv_twi_tx() is not blocking in you code, meaning the actual twi transfer will occur in the background, and the twi_handler() will return an NRF_DRV_TWI_EVT_DONE on complete twi transfer. If you want the nrf_drv_twi_tx() to be blocking and not return to main until complete, then you should call nrf_drv_twi_init() without the callback handler (use NULL as parameter instead of twi_handler).&lt;/p&gt;
&lt;p&gt;Since you are setting up the twi transfer with callback, and you set the breakpoint directly after nrf_drv_twi_tx(), it will be unpredictable whether the twi transfer is complete or not when the CPU is halted. You should instead set breakpoint on NRF_DRV_TWI_EVT_DONE in twi_handler() or use the driver in blocking mode.&lt;/p&gt;
&lt;p&gt;The reason the second trace show the twi pins to be low level before the twi transfer is likely because you have configured the twi pins as output somewhere earlier, this will not be seen on the first trace due to the breakpoint on line 283.&lt;/p&gt;
&lt;p&gt;Edit:&lt;/p&gt;
&lt;p&gt;The second trace show a NACK condition, most likely because the twi slave is not ready to receive data. Add a delay and try again. Check the datasheet for the twi slave for timing details.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>