<?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>S210 &amp;amp; twi - timing / speed</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/10434/s210-twi---timing-speed</link><description>Dear all, 
 I use nrf51422 with S210 soft device. I need to read an attached sensor via TWI. The sensor returns 32 bits of data. I need to read that 100 times a second.
I defined a timer running off the low speed clock source ( which is needed for the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 25 Nov 2015 14:00:27 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/10434/s210-twi---timing-speed" /><item><title>RE: S210 &amp; twi - timing / speed</title><link>https://devzone.nordicsemi.com/thread/38789?ContentTypeID=1</link><pubDate>Wed, 25 Nov 2015 14:00:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e2086958-ddd7-4111-8239-1ceff53b2a93</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Yes, referring to Table 18 in S210 SDS, tISR_ANT can be up to 321 μs. This would block execution of code at APP_LOW or MAIN priority for up to that amount of time.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: S210 &amp; twi - timing / speed</title><link>https://devzone.nordicsemi.com/thread/38790?ContentTypeID=1</link><pubDate>Wed, 25 Nov 2015 13:53:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c7154bc6-7151-47d2-98cc-d6cf29b17dc6</guid><dc:creator>WolfgangEbersbach</dc:creator><description>&lt;p&gt;Einar, I have seen this. So, yes, by documentation it may be that the master stretches the clock. But &amp;gt; 100usec ?
Anyhow, thanks for the help, I&amp;#39;ll close this now as I have other, more urgent things to solve before I come back to this fine tuning issue.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: S210 &amp; twi - timing / speed</title><link>https://devzone.nordicsemi.com/thread/38791?ContentTypeID=1</link><pubDate>Wed, 25 Nov 2015 13:39:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3dfca2fa-8a56-4cb7-b6fc-cee918cd5f5b</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Regarding the first quote, I copy-pasted the wrong section. I have updated the answer with what I indented to include. Thanks for noticing.&lt;/p&gt;
&lt;p&gt;You are using the hardware peripheral. What I wanted to point out with the quotes is that the CPU has to write and read each byte separately to the TWI peripheral registers, and if the CPU cannot do this in time, the transfer will be delayed.&lt;/p&gt;
&lt;p&gt;If you look at the Processor availability section (11.2) of the SoftDevice Specification, you will see that you can expect high priority interrupts some times when using ANT, and the duration of these events are of the order you are seeing (See Table 18 of the S210 Soft Device Spec).&lt;/p&gt;
&lt;p&gt;The nRF52 however has a new set of TWI peripherals (TWIM/TWIS) which has DMA. So with the nRF52 should be able to do the transfers consistently without the delay even while doing ANT communication (or processing any other high priority interrupts).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: S210 &amp; twi - timing / speed</title><link>https://devzone.nordicsemi.com/thread/38788?ContentTypeID=1</link><pubDate>Wed, 25 Nov 2015 12:42:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2e334f52-10e6-4ad9-bb9d-0495af50032f</guid><dc:creator>WolfgangEbersbach</dc:creator><description>&lt;p&gt;Hi Einar,&lt;/p&gt;
&lt;p&gt;thanks for the response. What you refer to is HW related delays, like copying 8 bits from a register to somewhere. Anyhow, I see delays of 70usec between the write transfer and the read transfer. And about 25usec between the first read byte and the 2nd one. And &amp;gt; 100usec between the end of one read transfer and the start of the next write transfer. These numbers are WAY too big to be caused by hardware. I have seen the softdevice document, according to that the TWI is free to be used. Also, interrupt latency additions caused by the soft device are all 1-digit numbers.&lt;/p&gt;
&lt;p&gt;Sadly (at least to me) the SDK is extremely scattered into a million files, #defines and macros all over the place so that it is really really hard to understand the example codes.&lt;/p&gt;
&lt;p&gt;So, if I use app_twi, does that actually use hardware TWI ? Or is that bit-banged software TWI ?&lt;/p&gt;
&lt;p&gt;In any case there is some delays hidden somewhere. Maybe they are required for whatever reason, maybe not. I just try to get the TWI transfers done as quick as possible to save energy. My TWI sensor has quite high power consumption, so any usec more sleep on the sensor side pays off a lot...&lt;/p&gt;
&lt;p&gt;According to the NRF51 datasheet there is hardware TWI. On page 58 of the DS you can see that the longest delay required by hardware is 5,2 usec for start / stop conditions. So, there is no hardware reason for 2 or even 3 digit delay times.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ll put some more time in this as soon as I managed to gain control over the GPIO&amp;#39;s in the ant_bpwr_tx example code - which is hard due to the way the board support and app_button stuff is buried everywhere in the example code. I would much more prefer example code that is as minimal as possible. Yes, including having register addresses and such directly in the code instead of hidden behind 15 #include/#ifdef/#macro things.&lt;/p&gt;
&lt;p&gt;Regards, Wolfgang.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: S210 &amp; twi - timing / speed</title><link>https://devzone.nordicsemi.com/thread/38792?ContentTypeID=1</link><pubDate>Wed, 25 Nov 2015 10:37:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a395021b-973f-47c9-9f1c-9dd45b0efc7e</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;I think you have answered most of your question in your comment. I will try to add some more details.&lt;/p&gt;
&lt;p&gt;The TWI transmitter and receiver are single buffered so the CPU has to do some work between every byte. As stated in Section 28.4 of the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf51.v1.0.0/pdflinks/ref_manual.html?cp=2_2"&gt;reference manual&lt;/a&gt; for write:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;If the CPU is prevented from writing to TXD when the TWI master is ready to clock out a byte, the TWI
master will stretch the clock until the CPU has written a byte to the TXD register.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;and read:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;After receiving a byte, the TWI master will delay sending the ACK/NACK bit by stretching the clock until the
CPU has extracted the received byte, that is, by reading the RXD register.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Section 11.2 of the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.210.sds.v1.0.0/s210.html?cp=2_7_3"&gt;SoftDevice Specification&lt;/a&gt; describes the processor availability and latencies for the interrupts/priorities available to the application. This seems to match with the pauses you sometimes see in the TWI transfers.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: S210 &amp; twi - timing / speed</title><link>https://devzone.nordicsemi.com/thread/38787?ContentTypeID=1</link><pubDate>Tue, 24 Nov 2015 12:32:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:84e80ba0-5920-4f8c-afe4-5bb2aa084262</guid><dc:creator>WolfgangEbersbach</dc:creator><description>&lt;p&gt;OK, I put the TWI transfers out of the timer ISR. Now I just set a flag in the ISR and do the TWI transaction within the main loop. This allows for the 100 TWI transactions per second. Every now and then the transaction is paused by 5.something msec. This likely is the s210 processing the ANT stuff.
Remains the question why the TWI transaction itself has these delays in it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>