<?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>NRF52 not reading third SPI byte</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/42257/nrf52-not-reading-third-spi-byte</link><description>Hi 
 I am trying to port an SPI driver from a project for the NRF51822 to an NRF52832 and running into a problem reading more than two bytes. We are using SPI0 (not SPIM0) connected to an external flash chip. 
 Below is an image capturing an example of</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 18 Jan 2019 21:41:30 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/42257/nrf52-not-reading-third-spi-byte" /><item><title>RE: NRF52 not reading third SPI byte</title><link>https://devzone.nordicsemi.com/thread/166595?ContentTypeID=1</link><pubDate>Fri, 18 Jan 2019 21:41:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7f425632-1500-4af4-8db6-60a358b43270</guid><dc:creator>Nguyen Hoan Hoang</dc:creator><description>&lt;p&gt;Can use this &lt;a href="https://github.com/I-SYST/EHAL/blob/master/ARM/Nordic/src/spi_nrf5x.cpp"&gt;SPI driver code&lt;/a&gt; as reference. &amp;nbsp;Same code works across nRF5x series with supports for both master/slave, IO or DMA.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 not reading third SPI byte</title><link>https://devzone.nordicsemi.com/thread/166591?ContentTypeID=1</link><pubDate>Fri, 18 Jan 2019 18:25:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5f24b09b-3253-4136-badb-a9a97ef93e64</guid><dc:creator>David Andresky</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;// Refer to &amp;quot;Figure 58: SPI master transaction&amp;quot; in the nrf51 reference manual
void spi_master_transfer(uint8_t const * p_tx_buf, size_t tx_buf_len, uint8_t * p_rx_buf, size_t rx_buf_len)
{
    VERIFY_TRUE_VOID(spi_master.open);
    VERIFY_TRUE_VOID(BIT_IS_CLEAR(NRF_GPIO-&amp;gt;OUT, spi_master.pin_slave_select));

    size_t const max_length = MAX(tx_buf_len, rx_buf_len);

    VERIFY_TRUE_VOID(max_length &amp;gt; 0);

    size_t bytes_sent = 0;
    size_t bytes_received = 0;

    // kick off the process by loading the double buffered TXD
    for (int i=0; i&amp;lt;2; i++)
    {
        if (bytes_sent &amp;lt; max_length)
        {
            if (p_tx_buf != NULL &amp;amp;&amp;amp; bytes_sent &amp;lt; tx_buf_len)
            {
                NRF_SPI-&amp;gt;TXD = p_tx_buf[bytes_sent];
            }
            else
            {
                // send a dummy byte in order to facilitate reading bytes we care about
                NRF_SPI-&amp;gt;TXD = SPI_DEFAULT_TX_BYTE;
            }
            bytes_sent++;
        }
    }

    uint8_t rx_byte;

    while (bytes_received &amp;lt; max_length)
    {
        while (!NRF_SPI-&amp;gt;EVENTS_READY) {}   // TODO: driver locks up here with optimization at O3

        rx_byte = NRF_SPI-&amp;gt;RXD;

        if (p_rx_buf != NULL &amp;amp;&amp;amp; bytes_received &amp;lt; rx_buf_len)
        {
            p_rx_buf[bytes_received] = rx_byte;
        }
        bytes_received++;

        if (bytes_sent &amp;lt; max_length)
        {
            if (p_tx_buf != NULL &amp;amp;&amp;amp; bytes_sent &amp;lt; tx_buf_len)
            {
                NRF_SPI-&amp;gt;TXD = p_tx_buf[bytes_sent];
            }
            else
            {
                // send a dummy byte in order to facilitate reading bytes we care about
                NRF_SPI-&amp;gt;TXD = SPI_DEFAULT_TX_BYTE;
            }
            bytes_sent++;
        }
        
        // Note: Initial implementation for the nRF51 based modules did not require these nop&amp;#39;s. However, the nRF52 was failing
        // the self-test and after some investigation I discovered that the third byte in the read_jedec_id command was being
        // transfered by the chip but was not being read into the rx buffer. After reading paragraph 48.1.3, SPI master transaction
        // sequence, of the product specification I attempted the nop&amp;#39;s and was able to read in the third byte and pass the test.
        // I first attempted 5 nop&amp;#39;s but saw no change. I then arbitrarily tried 15 nop&amp;#39;s and saw success. I added 5 more for
        // good measure but the bootloader was not working so I increased to 40 and all issues were resolved.
        if(bytes_received == 2)
        {
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
            __asm(&amp;quot;nop&amp;quot;);
        }
    }

    NRF_SPI-&amp;gt;EVENTS_READY = 0;
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 not reading third SPI byte</title><link>https://devzone.nordicsemi.com/thread/165917?ContentTypeID=1</link><pubDate>Wed, 16 Jan 2019 10:36:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:754da547-7fd1-4812-932a-143635258ecc</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;&lt;strong&gt;Thanks for lettings us know about this&lt;/strong&gt;. I do not understand why this fixes the issue. They should not have been needed if you are reading them on the condition of getting READY event.&lt;/p&gt;
&lt;p&gt;Just for future reference, can you please give us the code snippet to have a little more insights about the driver state at the time you add these nops.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 not reading third SPI byte</title><link>https://devzone.nordicsemi.com/thread/165552?ContentTypeID=1</link><pubDate>Mon, 14 Jan 2019 15:39:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9c3c89cd-c084-40d2-a1f2-8a47b3a2c4df</guid><dc:creator>David Andresky</dc:creator><description>&lt;p&gt;Hi Susheel,&lt;/p&gt;
&lt;p&gt;We have our own driver, and like I said, it works on the NRF51.&lt;/p&gt;
&lt;p&gt;In section 48.1.3 of the product specification there are a couple paragraphs about the READY event and reading bytes B and C. It is difficult to interpret but on a whim I decided to add 15 nops&amp;nbsp;before reading in the third byte and this fixed the issue. The 15 nops added another half clock cycle to the gap and now I can read the data. I have run tests reading thousands of bytes in 256 byte increments without failure.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 not reading third SPI byte</title><link>https://devzone.nordicsemi.com/thread/164658?ContentTypeID=1</link><pubDate>Wed, 09 Jan 2019 09:51:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7e5eee77-ed5b-4f9b-a871-385b503f36f1</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;You should still be able to use the SPI module. I am guessing/hoping that you are using latest SDK drivers to communicate to your SPI module on nRF52832.&amp;nbsp; We have not known any other issue apart from the extra clock issue already mentioned in the Errata and this one does not match your symptoms.&lt;/p&gt;
&lt;p&gt;Try your communication using SDK15.2 nrfx_spi.c driver&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>