<?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>Strange behaviour SPI_MASTER peripheral</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/11067/strange-behaviour-spi_master-peripheral</link><description>Dear Nordic developers, 
 SPI_MASTER peripheral behaves in a way, that I cannot understand from manual is it normal or no. 
 I have implemented something similar to loopback example.
After initialization I&amp;#39;m writing first byte to the TXD register and</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 13 Jan 2016 11:14:21 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/11067/strange-behaviour-spi_master-peripheral" /><item><title>RE: Strange behaviour SPI_MASTER peripheral</title><link>https://devzone.nordicsemi.com/thread/41401?ContentTypeID=1</link><pubDate>Wed, 13 Jan 2016 11:14:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:68b60810-14a1-4ef6-bd4b-2ea54108480a</guid><dc:creator>haruthakop</dc:creator><description>&lt;p&gt;Thanks a lot for your answer, You are very helpful again.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Strange behaviour SPI_MASTER peripheral</title><link>https://devzone.nordicsemi.com/thread/41399?ContentTypeID=1</link><pubDate>Wed, 13 Jan 2016 10:53:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7f7b36b9-d346-456d-bbe6-d6254fd135cc</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;The second READY event will be generated exactly after you read the first byte, that will make RXD-1 byte to move in RXD and will generate second READY event.&lt;/p&gt;
&lt;p&gt;You can do it the other way around, execute your ISR every first READY event and ignore the second Ready event.
You cannot ignore the first because if you do not read RXD in first ready event then you wont get second ready event. This is because ready event is generated when the byte moves from RXD-1 to RXD internal buffer.&lt;/p&gt;
&lt;p&gt;You solution will work for reading two bytes in first event and ignoring the second with a minor twist. Look at the code below.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void SPI0_TWI0_IRQHandler(void)
{
    if ((NRF_SPI0-&amp;gt;EVENTS_READY == 1) &amp;amp;&amp;amp; (NRF_SPI0-&amp;gt;INTENSET &amp;amp; SPI_INTENSET_READY_Msk))
    {
        NRF_SPI0-&amp;gt;EVENTS_READY = 0;
        if (first_ready_event)
        {
           rx_data[0] = (uint8_t)spi_base-&amp;gt;RXD;
           while(NRF_SPI0-&amp;gt;EVENTS_READY != 1);   // clear the second event here
           NRF_SPI0-&amp;gt;EVENTS_READY = 0;
           rx_data[1] = (uint8_t)spi_base-&amp;gt;RXD;
        }
     if (second_ready_event)
     // do nothing
    }
}


 int main()
 {
    while(true)
    {
       master_spi-&amp;gt;TXD =cnt;
       master_spi-&amp;gt;TXD =cnt + 1;
       nrf_delay_us(100);
    }
  }
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Strange behaviour SPI_MASTER peripheral</title><link>https://devzone.nordicsemi.com/thread/41400?ContentTypeID=1</link><pubDate>Wed, 13 Jan 2016 10:23:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5bc50b7b-b178-46a2-bb1d-ffa6afad78fe</guid><dc:creator>haruthakop</dc:creator><description>&lt;p&gt;Hi Aryan, Thanks a lot for your response. You are right. I have tested with Oscilloscope and I can see that second ready event is coming earlier than I&amp;#39;m reading second byte after first byte.&lt;/p&gt;
&lt;p&gt;I tried out all this, because I have very tight timing requirements. I need to receive two bytes every 100 us and I want if possible to skip the first READY event and go to ISR to every second READY event and read two bytes together. Is there possibility to do that?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Strange behaviour SPI_MASTER peripheral</title><link>https://devzone.nordicsemi.com/thread/41398?ContentTypeID=1</link><pubDate>Tue, 12 Jan 2016 14:35:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:34f7c1b5-2ab0-409a-9310-711b136a877d</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Hi harutakop,&lt;/p&gt;
&lt;p&gt;Sorry for the late reply.&lt;/p&gt;
&lt;p&gt;The behaviour you see is normal because you are pushing two bytes into TX buffer so fast. So when the first byte is received after transmitting &lt;code&gt;master_spi-&amp;gt;TXD =cnt;&lt;/code&gt; the ISR starts executing and before you start reading the RXD buffer, the second byte is also transmitted &lt;code&gt;master_spi-&amp;gt;TXD =cnt + 1;&lt;/code&gt; and equivalent byte received. If you change you code little  you will be able to see two READY events&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void SPI0_TWI0_IRQHandler(void)
{
    if ((NRF_SPI0-&amp;gt;EVENTS_READY == 1) &amp;amp;&amp;amp; (NRF_SPI0-&amp;gt;INTENSET &amp;amp; SPI_INTENSET_READY_Msk))
    {
        NRF_SPI0-&amp;gt;EVENTS_READY = 0;
        if (first_ready_event)
        {
           rx_data[0] = (uint8_t)spi_base-&amp;gt;RXD; // as soon as you do this RXD-1 value is pushed into RXD and this will cause the READY event again
        }
     if (second_ready_event)
     {
           rx_data[1] = (uint8_t)spi_base-&amp;gt;RXD;
     }
    }
}


 int main()
 {
    while(true)
    {
       master_spi-&amp;gt;TXD =cnt;
       master_spi-&amp;gt;TXD =cnt + 1;
       nrf_delay_us(100);
    }
  }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To summarize, what you are seeing is normal because you are pushing two bytes so fast in double buffered SPITX that it is able to serialize them. It might actually JUST finished transmitted the second byte before you read the first byte in ISR. This will not work if you do this&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; int main()
 {
    while(true)
    {
       master_spi-&amp;gt;TXD =cnt;
       master_spi-&amp;gt;TXD =cnt + 1;
       master_spi-&amp;gt;TXD =cnt + 2;
       nrf_delay_us(100);
    }
  }
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>