<?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>Cannot get 400 kbps TWI_SW frequancy with clock stretching</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/9763/cannot-get-400-kbps-twi_sw-frequancy-with-clock-stretching</link><description>Hi Nordic developers, 
 I&amp;#39;m using TWI software driver provided by NORDIC.
I need to have 400 kbps frequancy.
I have seted TWI_DELAY() to 0 and TWI_MASTER_TIMEOUT_COUNTER_LOAD_VALUE to 1000. (for clock stretching) 
 Just checking with osciloscope SCL</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 21 Oct 2015 11:31:34 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/9763/cannot-get-400-kbps-twi_sw-frequancy-with-clock-stretching" /><item><title>RE: Cannot get 400 kbps TWI_SW frequancy with clock stretching</title><link>https://devzone.nordicsemi.com/thread/36168?ContentTypeID=1</link><pubDate>Wed, 21 Oct 2015 11:31:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9cb6e819-9fd5-4f9d-8e68-2f6c2046f302</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;No problem. The driver was completely redesigned in SDK 8.1.0. The SDK team strives to design new drivers that is compatible with both nRF51 and the new 52. So it is hard to keep up with all the new releases.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot get 400 kbps TWI_SW frequancy with clock stretching</title><link>https://devzone.nordicsemi.com/thread/36167?ContentTypeID=1</link><pubDate>Wed, 21 Oct 2015 11:11:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:65e8996d-18c4-4c56-b3f5-881ef02a60de</guid><dc:creator>chinargor</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thanks a lot for your help. Actually for some reasons I&amp;#39;m using twi_hw_master library (not nrf_drv_twi). But your idea is interesting and can also be implemented in twi_hw_master. Thanks again&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot get 400 kbps TWI_SW frequancy with clock stretching</title><link>https://devzone.nordicsemi.com/thread/36166?ContentTypeID=1</link><pubDate>Wed, 21 Oct 2015 08:02:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1aa1cd76-55ef-47c2-8e75-fa84ce83e5ec</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;You can set up a TWI interrupt handler. In the handler you can listen for TWI errors, e.g. the NACK after address event. I have attached an example in the answer above. It scans all possible TWI addresses and toggles a pin on every address NACK. If it finds a device on a specific address and an ACK is returned you will see that the pin does not toggle. The example use the TWI drivers found in SDK 9.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot get 400 kbps TWI_SW frequancy with clock stretching</title><link>https://devzone.nordicsemi.com/thread/36169?ContentTypeID=1</link><pubDate>Mon, 19 Oct 2015 12:06:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bc93253e-2a63-42ac-8a1b-e302d63319ae</guid><dc:creator>chinargor</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve modified a little bit the twi_sw_master.c driver and was able to reach 400kHz with timeout enabled.
Instead of using twi_master_wait_while_scl_low() function I&amp;#39;m using the twi_master_wait_while_scl_low()  macro shown bellow.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; #define twi_master_wait_while_scl_low()	do{                                             \
    TWI_SCL_HIGH();	                                                                        \
    while(TWI_SCL_READ() == 0 &amp;amp;&amp;amp; timeout_counter != TWI_MASTER_TIMEOUT_COUNTER_LOAD_VALUE)	\
    {								\
        timeout_counter++;		    \
    }						        \
    } while(0)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And in every function were this macro is used I&amp;#39;ve added&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; #if TWI_MASTER_TIMEOUT_COUNTER_LOAD_VALUE != 0
    uint32_t volatile timeout_counter = 0;
 #endif
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Just check with the Oscilloscope I&amp;#39;m getting 2.4us SCL cycle.
Please correct me if I&amp;#39;m doing something wrong.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot get 400 kbps TWI_SW frequancy with clock stretching</title><link>https://devzone.nordicsemi.com/thread/36165?ContentTypeID=1</link><pubDate>Mon, 19 Oct 2015 06:26:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b1cf7d8e-a50c-4209-b178-bb183423747a</guid><dc:creator>chinargor</dc:creator><description>&lt;p&gt;Hi, Thanks a lot for your answer.&lt;/p&gt;
&lt;p&gt;I cannot use the hardware driver, because after sending a device address I need to get an acknowledgment. But in this case I get a TXDSENT event only after sending first databyte.&lt;/p&gt;
&lt;p&gt;If there is a way to check, whether device address is correct and the acknowledgment is successfuly recieved I&amp;#39;d very happy to use hardware driver.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot get 400 kbps TWI_SW frequancy with clock stretching</title><link>https://devzone.nordicsemi.com/thread/36164?ContentTypeID=1</link><pubDate>Fri, 16 Oct 2015 12:55:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:94bdea28-3697-4fa4-9a3f-712838c0b2b7</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Whenever you set &lt;em&gt;TWI_MASTER_TIMEOUT_COUNTER_LOAD_VALUE&lt;/em&gt; to a non-zero value you will have an if-statement in &lt;em&gt;twi_master_wait_while_scl_low()&lt;/em&gt;. This if-statement decrements &lt;em&gt;timeout_counter&lt;/em&gt; and compares it to zero. These few instructions take time and are the cause of  your additional 0.5us. Hence, you cannot reach 400kHz with timeout enabled.&lt;/p&gt;
&lt;p&gt;But may I ask why you use the software driver and not the hardware driver?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;EDIT:&lt;/strong&gt; Example &lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/twi_2D00_nack_2D00_after_2D00_address.zip"&gt;twi-nack-after-address.zip&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot get 400 kbps TWI_SW frequancy with clock stretching</title><link>https://devzone.nordicsemi.com/thread/36163?ContentTypeID=1</link><pubDate>Fri, 16 Oct 2015 10:59:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:20c9def8-05a4-457b-a211-164bd58d1838</guid><dc:creator>JohnBrown</dc:creator><description>&lt;p&gt;Out of curiosity, why do you need 400k?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>