<?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>nRF51822 SPI master</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/9626/nrf51822-spi-master</link><description>Hi! 
 I have custom board with nRF51822 and I need to communicate with serial flash W25X40 using SPI master example with SoftDevice enabled (S110 is used). I worked with serial flashes before but didn&amp;#39;t encountered the problems described below. 
 During</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 16 Oct 2015 13:15:51 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/9626/nrf51822-spi-master" /><item><title>RE: nRF51822 SPI master</title><link>https://devzone.nordicsemi.com/thread/35588?ContentTypeID=1</link><pubDate>Fri, 16 Oct 2015 13:15:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:de1af745-e167-4400-8ba7-6668db6d1bc1</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thanks to all for the answers.&lt;/p&gt;
&lt;p&gt;So far I couldn&amp;#39;t resolve the issue but I&amp;#39;ve found another library which I used to implement all I need (erasing flash, reading and writing the data). The library is attached: &lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/0777.spi_5F00_master.zip"&gt;spi_master.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If someone is going to use the library do the following:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Change pins definition in header file (CLK, MISO, MOSI, CS) according to your schematic design.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Call spi_master_init from main file or from the library which is based on the library I&amp;#39;ve attached. For example, if SPI0 is used in the mode 0 with MSB first call the function:&lt;/p&gt;
&lt;p&gt;spi_base_address = spi_master_init(SPI0, SPI_MODE0, (bool)0);&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use function &lt;strong&gt;spi_master_tx_rx&lt;/strong&gt; to send/receive data. For example, in my case mentioned in the first post the code&lt;/p&gt;
&lt;p&gt;tx_data[0] = 0x9F;&lt;/p&gt;
&lt;p&gt;spi_master_tx_rx(spi_base_address, 4, (const uint8_t *)tx_data, rx_data);&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;will return SPI flash ID in the rx_data array.&lt;/p&gt;
&lt;p&gt;Hope this helps.&lt;/p&gt;
&lt;p&gt;Regards,
Dmitry.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51822 SPI master</title><link>https://devzone.nordicsemi.com/thread/35587?ContentTypeID=1</link><pubDate>Mon, 12 Oct 2015 12:36:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ec8cc92a-7b10-4bca-b4ec-b2d5be446368</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Hi. I have experimented for a while now and using your code I see the same behaviour as you do. Although I haven&amp;#39;t been able to pinpoint exactly what is happening @Nathan is correct. Calling spi_master_send_recv() consecutively without waiting for the previous transmission to end will fail.&lt;/p&gt;
&lt;p&gt;A simple solution that works for me is to set a flag in the spi event handler like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void spi_master_event_handler(spi_master_evt_t spi_master_evt)
{
    if(spi_master_evt.evt_type == SPI_MASTER_EVT_TRANSFER_COMPLETED)
        m_transfer_completed = true;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and then wait with a while loop for transmission 1 to complete before you start transmission 2:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;while(!m_transfer_completed);
m_transfer_completed = false;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It sounds like you have tried to implement something like this though? Do you mind sharing you code?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51822 SPI master</title><link>https://devzone.nordicsemi.com/thread/35586?ContentTypeID=1</link><pubDate>Fri, 09 Oct 2015 05:46:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:39c91aae-ee86-49ca-8e6c-683eaa5e8d3f</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;Hi Nathan,&lt;/p&gt;
&lt;p&gt;Thanks for the reply.&lt;/p&gt;
&lt;p&gt;I added the feature you talk about but I guess the problem lies elsewhere. I&amp;#39;ve found a mistake but it doesn&amp;#39;t solves the problem: when calling&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;spi_master_send_recv(SPI_MASTER_0, tx_data, 4, rx_data, 1);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I should use value 5 instead 4 because master latches transfer from slave during 5th byte. Accordingly RX buffer should have 5 elements instead 4 in my case.&lt;/p&gt;
&lt;p&gt;The issue which is still there is that &lt;strong&gt;spi_master_send_recv&lt;/strong&gt; function changes TX buffer contents to the original value although new value is passed as an argument: in my case if step in the function during second call I observe that tx_data[0] assigned by 0x9F. This occurs when the following instruction has been called:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;volatile spi_master_instance_t * p_spi_instance = spi_master_get_instance(
    spi_master_hw_instance);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Any thoughts?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51822 SPI master</title><link>https://devzone.nordicsemi.com/thread/35585?ContentTypeID=1</link><pubDate>Thu, 08 Oct 2015 17:55:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:37e181d6-d9e1-412a-b868-aeddb03b78b7</guid><dc:creator>Nathan</dc:creator><description>&lt;p&gt;Dmitry,&lt;/p&gt;
&lt;p&gt;The spi_master_send_recv function is non-blocking, it just kicks off the SPI hardware to start the transaction. When the transaction is completed, an interrupt will fire and call the event handler you passed to the spi_master_init function (in your case, spi_master_event_handler). You need to wait for the event hander to be called with the SPI_MASTER_EVT_TRANSFER_COMPLETED event type before calling spi_master_send_recv again with the new data.&lt;/p&gt;
&lt;p&gt;Alternatively, you can use the uint32_t return value of spi_master_send_recv to determine when data has been sent successfully. The function will return NRF_SUCCESS if the data was added to the SPI output correctly, or it will return NRF_ERROR_BUSY if a transaction is currently in progress and the data will not be sent.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>