<?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>SPI inter-byte duration</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/14824/spi-inter-byte-duration</link><description>Hello, I&amp;#39;ve been working on porting a bit-banged control of a peripheral to use nRF51 SPI--which is just SPI rather than SPIM (therefore no DMA). Observe the SPICLK waveform when I choose 4 MHz:
 
 The byte itself is emitted at 4 MHz. But the huge inter</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 01 Jul 2016 12:58:07 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/14824/spi-inter-byte-duration" /><item><title>RE: SPI inter-byte duration</title><link>https://devzone.nordicsemi.com/thread/56593?ContentTypeID=1</link><pubDate>Fri, 01 Jul 2016 12:58:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:81e64f14-0165-4356-a1e6-cea349c4068b</guid><dc:creator>Henry Choi</dc:creator><description>&lt;p&gt;Thanks for the example code Hung.  Yes, that is essentially what I am doing.  It&amp;#39;s strange because calling sd_app_evt_wait() for the SPI0 is working fine--and it was working fine even BEFORE I put in the SCB_SCR_SEVONPEND_Msk or NVIC_ClearPendingIRQ(SPI0_TWI0_IRQn).  So WFE() returned for SPI0 when it shouldn&amp;#39;t have, and now UART0 WFE is NOT returning when it should?!&lt;/p&gt;
&lt;p&gt;The production code is quite a bit more complex, so I really can&amp;#39;t isolate it effectively--nor do I have the time to undo all the debugging  setup.  This is not the 1st time where I had this kind of predicament --unable to run small isolation code due to the complexity of the full setup.  I should just buy another nRF51 DK board and set it up as an isolation bed.&lt;/p&gt;
&lt;p&gt;I need to solve a more pressing problem, so I&amp;#39;ll come back to this later (perhaps when I get another nRF51 DK).  Thanks Hung.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI inter-byte duration</title><link>https://devzone.nordicsemi.com/thread/56592?ContentTypeID=1</link><pubDate>Fri, 01 Jul 2016 10:49:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bfc3b401-35aa-4466-a962-35f8b13770dd</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;@Henry: Could you double check ? It worked fine in my test. I attached the code here, SDK v7.2 S110 v7.1.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/experimental_5F00_ble_5F00_app_5F00_uart-_2D00_-Copy.zip"&gt;experimental_ble_app_uart - Copy.zip&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI inter-byte duration</title><link>https://devzone.nordicsemi.com/thread/56591?ContentTypeID=1</link><pubDate>Thu, 30 Jun 2016 17:37:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5702298f-3c5e-4bf1-9aa6-5bf940a31ab5</guid><dc:creator>Henry Choi</dc:creator><description>&lt;p&gt;I think POWER_CLOCK_IRQn is the IRQ I was looking for.  Anyway, I can&amp;#39;t seem to get the nRF to return from sd_app_evt_wait() using the technique you describe.  Can you please point out anything obviously wrong I am doing below:&lt;/p&gt;
&lt;p&gt;In init():&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    NRF_UART0-&amp;gt;ENABLE          = UART_ENABLE_ENABLE_Enabled;
    NRF_UART0-&amp;gt;INTENSET = UART_INTENSET_TXDRDY_Msk;//required to wake up from WFE
    NRF_UART0-&amp;gt;TASKS_STARTTX   = 1;
    NRF_UART0-&amp;gt;TASKS_STARTRX   = 1;
    SCB-&amp;gt;SCR |= SCB_SCR_SEVONPEND_Msk;

void put_byte(uint8_t b) {
    NRF_UART0-&amp;gt;TXD = b;
    while (!NRF_UART0-&amp;gt;EVENTS_TXDRDY) {
        sd_app_evt_wait();
    }
    NRF_UART0-&amp;gt;EVENTS_TXDRDY = 0;
    NVIC_ClearPendingIRQ(UART0_IRQn);
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI inter-byte duration</title><link>https://devzone.nordicsemi.com/thread/56590?ContentTypeID=1</link><pubDate>Thu, 30 Jun 2016 16:22:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c21dc22a-4a6b-41c6-863e-975bca009126</guid><dc:creator>Henry Choi</dc:creator><description>&lt;p&gt;Thank you Hung, I found other information from this forum yesterday, but did not think about NVIC_ClearPending().  I found the interrupt number for SPI1 and UART0, but what is the corresponding NVIC number for NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED on nRF51822?  I don&amp;#39;t see it in the IRQn_Type enum...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI inter-byte duration</title><link>https://devzone.nordicsemi.com/thread/56589?ContentTypeID=1</link><pubDate>Thu, 30 Jun 2016 13:19:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1f3f796d-2e1e-4ac8-b59b-0932557bb92b</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;@Henry Choi:
I see, but from my understanding you should still enable the interrupt on READY event (with INTENSET register), if you want to wake CPU up when in WFE.&lt;/p&gt;
&lt;p&gt;Still from my understanding, what ARM described as &amp;quot;events from peripheral&amp;quot; actually are the events that are enabled as interrupts from the peripheral. Without enabling interrupt, the peripheral has no way to tell the CPU about its events.&lt;/p&gt;
&lt;p&gt;Also you need to enable SEVONPEND with SCB-&amp;gt;SCR |= SCB_SCR_SEVONPEND_Msk;  to wake the chip up from pended event.&lt;/p&gt;
&lt;p&gt;So, NVIC_EnableIRQ() is not needed if you don&amp;#39;t want to handle the interrupt, but INTENSET should be set, and also you should clear the interrupt pending flag NVIC_ClearPendingIRQ(XXX_IRQn); after it wake the chip up.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI inter-byte duration</title><link>https://devzone.nordicsemi.com/thread/56588?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2016 16:56:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:19773429-cc82-4957-94ab-c6b1fd5c0643</guid><dc:creator>Henry Choi</dc:creator><description>&lt;p&gt;I am indeed using the SD.  Just to be clear Hung, we are talking about WFE rather than WFI.  From &lt;a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDEAAHJ.html"&gt;ARM infocenter doc&lt;/a&gt;, WFE should return when an &amp;quot;event signaled by a peripheral ...&amp;quot; occurs.  Don&amp;#39;t you think the nRF peripheral EVENTS_XXXX all should lead to WFE() returning?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI inter-byte duration</title><link>https://devzone.nordicsemi.com/thread/56587?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2016 15:19:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a92be466-c62a-4286-8c63-b37e6a04ad99</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;@Henry: You should call sd_app_evt_wait() only if the softdevice is enabled. Otherwise you should call __WFE() instead. Have you made sure you enable interrupt for those event (NVIC_EnableIRQ) ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI inter-byte duration</title><link>https://devzone.nordicsemi.com/thread/56586?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2016 14:52:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4423dcfe-f4dc-41b4-bced-7451471f07c6</guid><dc:creator>Henry Choi</dc:creator><description>&lt;p&gt;Thank you for the reply Wojtek and Hung, you were right: I was taking much too long in my checking for the nrf_spi_event_check(p_spi, NRF_SPI_EVENT_READY).  There is still some ~4 us until I see the EVENT_READY flag in the register, but the effective BW is now up to 1.23 MHz (when using the 4 MHz SPI speed).  BTW, why can&amp;#39;t I call sd_app_evt_wait() (which just calls WFE) while waiting for NRF_SPI_EVENT_READY?  I find this to be true even while waiting for NRF_UART0-&amp;gt;EVENTS_TXDRDY (in another context) as well.  Shouldn&amp;#39;t these events wake up the nRF that is sleeping on WFE?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI inter-byte duration</title><link>https://devzone.nordicsemi.com/thread/56585?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2016 12:50:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0611dc67-e472-45a9-9541-5305e9fd1dca</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;@Henry: I agree with Wojtek, and have you made sure you read the RXD byte out right after you receive the READY event ? There is only 2 bytes in the RXD buffer, if you are failed to read the buffer the SPI won&amp;#39;t clock the next byte, this is shown at Figure 58 in the nRF51 reference manual.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI inter-byte duration</title><link>https://devzone.nordicsemi.com/thread/56584?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2016 09:38:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bb1ac281-6d5f-4de9-9b6a-6e206fe956f9</guid><dc:creator>Wojtek</dc:creator><description>&lt;p&gt;I think it is driver overhead that makes it so slow. Could you show your SPI-sending code?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>