<?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>Any ideas on how to decrease SPI overhead time?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/522/any-ideas-on-how-to-decrease-spi-overhead-time</link><description>With the maximum SPI speed of 8 Mbps, I was expecting to be able to send 2 bytes in just a little over 2 us, but it takes a lot longer. It appears that the mandatory event wait time between bytes (to avoid overwriting the first one) is about 4 us and</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 06 Nov 2014 04:08:27 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/522/any-ideas-on-how-to-decrease-spi-overhead-time" /><item><title>RE: Any ideas on how to decrease SPI overhead time?</title><link>https://devzone.nordicsemi.com/thread/2719?ContentTypeID=1</link><pubDate>Thu, 06 Nov 2014 04:08:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ba8a1d22-bdc6-4961-96c1-efb447ee38dc</guid><dc:creator>Clem Taylor</dc:creator><description>&lt;p&gt;In the case of interrupt driven SPI, most of the overhead comes from the dispatch latency through the softdevice. To increase the speed of my driver instead of handling one byte in/out per interrupt I just say:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;while (hw-&amp;gt;EVENTS_READY)
{
    hw-&amp;gt;EVENT_READY = 0;
    &amp;lt;send and receive&amp;gt;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This sped up my SPI code considerably with the side effect of staying in the interrupt handler for the entire transaction.&lt;/p&gt;
&lt;p&gt;It seems that even though the SPI interface is double buffered, it doesn&amp;#39;t seem like the interrupt is triggered when the first byte is clocked in/out. In the single byte case I see a delay of ~82 cycles from the falling edge of the clock to the rising edge of a gpio when I enter my handler. In the double byte case I see the same 82 cycle delay, but it happens on the falling edge of the 16th SPI clock not the 8th clock as I would have expected.&lt;/p&gt;
&lt;p&gt;As a result of handling multiple bytes per interrupt I saw one annoying side effect. The nrf51 seems to be dispatching the SPI interrupt even when EVENTS_READY is 0. When I handle just one EVENTS_READY per interrupt I never see a EVENTS_READY==0 on entry to the interrupt.  It looks like the internal interrupt bit pending is latched when the event happens. So handling multiple bytes per interrupt is only useful if your are doing fairly long transactions.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Any ideas on how to decrease SPI overhead time?</title><link>https://devzone.nordicsemi.com/thread/2718?ContentTypeID=1</link><pubDate>Thu, 26 Sep 2013 15:54:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2db826cf-aa5a-4c1e-84db-84179cb9b2c2</guid><dc:creator>Gil dePaula</dc:creator><description>&lt;p&gt;I was able to decrease the time from 10 us to 3 us by:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Doing some assignments ahead of time:
register uint8_t rxData;
register uint16_t * ptr = &amp;amp;(Data[0]);    // 2 bytes
register uint32_t* RxReg = (uint32_t*)&amp;amp;(dac_spi_base_address-&amp;gt;RXD);
register uint32_t* TxReg = (uint32_t*)&amp;amp;(dac_spi_base_address-&amp;gt;TXD);&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Removing the RXD read between the bytes (the one after the second byte is still needed)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Removing the while(event) between the bytes, and replacing the one after the second byte with a NOP delay sequence function.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Final code:&lt;/p&gt;
&lt;p&gt;// Enable slave (slave select active low)	&lt;/p&gt;
&lt;p&gt;NRF_GPIO-&amp;gt;OUTCLR = SYNC_BIT_POS;&lt;/p&gt;
&lt;p&gt;// Write upper byte		&lt;/p&gt;
&lt;p&gt;*TxReg = ((*ptr) &amp;gt;&amp;gt; 8);&lt;/p&gt;
&lt;p&gt;// Read Rx register (this one is not needed)	
//    rxData = *RxReg;&lt;/p&gt;
&lt;p&gt;// Write lower byte&lt;/p&gt;
&lt;p&gt;*TxReg = ((uint8_t)(*ptr));&lt;/p&gt;
&lt;p&gt;// Read Rx register&lt;/p&gt;
&lt;p&gt;rxData = *RxReg;&lt;/p&gt;
&lt;p&gt;// Just a bunch of NOPs to wait for the byte transmittal&lt;/p&gt;
&lt;p&gt;dac_delay_100s_of_ns();&lt;/p&gt;
&lt;p&gt;// Disable slave (slave select active low)&lt;/p&gt;
&lt;p&gt;NRF_GPIO-&amp;gt;OUTSET = SYNC_BIT_POS;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Any ideas on how to decrease SPI overhead time?</title><link>https://devzone.nordicsemi.com/thread/2717?ContentTypeID=1</link><pubDate>Wed, 25 Sep 2013 15:20:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9af2209f-c088-4acc-89ae-94789620b21a</guid><dc:creator>Gil dePaula</dc:creator><description>&lt;p&gt;I think I may not need the first while() because the TXD is double-buffered, right?
Is the read of the RXD register mandatory?  (I don&amp;#39;t care about the received data).&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;
&lt;p&gt;Gil&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>