<?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>best practices to nrf_drv_spi_transfer sequentially</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/44849/best-practices-to-nrf_drv_spi_transfer-sequentially</link><description>Hello, 
 Currently, I am using the SDK15.2, BLE and two nRF52 DK boards, one using SPI master, and the other being the SPI Slave, between the SPIs and SPI master I added an extra line, allowing the slave to signal the master when it has data to send using</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 19 Mar 2019 13:25:03 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/44849/best-practices-to-nrf_drv_spi_transfer-sequentially" /><item><title>RE: best practices to nrf_drv_spi_transfer sequentially</title><link>https://devzone.nordicsemi.com/thread/177030?ContentTypeID=1</link><pubDate>Tue, 19 Mar 2019 13:25:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ffaa529e-aaff-4571-a342-466c98832c1a</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Do you have any logic analyzer trace? I would like to check that the SPI transaction looks good. This can be checked by looking at the CSN line toggling as expected between each transfer and there is a SPI clock present for each transfer. If that all looks good, then I think the problem may be the SPI slave implementation not able to handle the transfers fast enough (~thereby a 85us delay is required). You may also for test try to tie MISO to MOSI, and check if you loopback the correct data, this can confirm that the SPI master works as intended here.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: best practices to nrf_drv_spi_transfer sequentially</title><link>https://devzone.nordicsemi.com/thread/176828?ContentTypeID=1</link><pubDate>Mon, 18 Mar 2019 23:38:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4dcf61af-90fa-4939-b8d3-b0b2329b7d4f</guid><dc:creator>wpaul</dc:creator><description>[quote userid="71716" url="~/f/nordic-q-a/44849/best-practices-to-nrf_drv_spi_transfer-sequentially"]2) which&amp;nbsp;is the difference between SPI master and SPIM driver?[/quote]
&lt;p&gt;There are a couple of ways to use the SPI controller: using programmed I/O and using EasyDMA.&lt;/p&gt;
&lt;p&gt;Using the programmed I/O approach, you basically just write data a byte at a time into the SPI TX data register, and the SPI controller will wiggle the MOSI pin to match the bits. For completion, you can either test a status register in a loop or you can wait for a completion interrupt to trigger.&lt;/p&gt;
&lt;p&gt;With EasyDMA, you don&amp;#39;t need to send each byte one at a time: you give the controller the address of the buffer you want to send and its length and then start a DMA transfer. The controller will clock all the bits out for the whole buffer. Again, you can test a status register for transfer completion or wait for a completion interrupt.&lt;/p&gt;
&lt;p&gt;Note that except for the SPIM4 controller in the nRF52840, you can only use EasyDMA to send 255 bytes at a time. With the SPIM4 controller on the nRF52840, I think this is increased to 65536 bytes. Also, SPIM4 supports clock speeds up to 32MHz. (The other controllers are limited to 8MHz.)&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not sure of your context when you say &amp;quot;SPI master&amp;quot; but in a general sense, it implies the master side of the transfer (i.e. not the slave). SPIM implies that the controller is a master _and_ that is uses DMA instead of PIO for handling transfers.&lt;/p&gt;
&lt;p&gt;I think the older nRF52 design only supported the PIO mode, then they added EasyDMA mode for later chips. The same applies for the TWI (I2C) controller.&lt;/p&gt;
[quote userid="71716" url="~/f/nordic-q-a/44849/best-practices-to-nrf_drv_spi_transfer-sequentially"]3) are there differences&amp;nbsp;between SPI (clock rate, easy DMA) on nRF52832 and nRF52840?[/quote]
&lt;p&gt;The nRF52840 has one high speed SPIM controller (SPIM4) which supports clock speeds up to 32MHz. The nRF52832 is limited to 8MHz for all controllers. Also, the SPIM controllers on the nRF52832 can only transfer 255 bytes at a time via EasyDMA (larger buffers are sent using multiple transfers). The high speed SPIM controller on the nRF52840 supports up to 65535 byte transfers. (I&amp;#39;m not sure offhand if that also applies to the low speed controllers too.)&lt;/p&gt;
&lt;p&gt;-Bill&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: best practices to nrf_drv_spi_transfer sequentially</title><link>https://devzone.nordicsemi.com/thread/176827?ContentTypeID=1</link><pubDate>Mon, 18 Mar 2019 23:23:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cd355f35-9e1c-49a4-adda-b87cc1943f61</guid><dc:creator>MeliodasD</dc:creator><description>&lt;p&gt;for example, I tried to replicate my issue with the SPI and SPIs original examples(both have RTT nrf_log enabled), where the only modification I did to the SPI Master example was:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;        // Reset rx buffer and transfer done flag
        memset(m_rx_buf, 0, m_length);
        spi_xfer_done = false;
        APP_ERROR_CHECK(nrf_drv_spi_transfer(&amp;amp;spi, m_tx_buf, m_length, m_rx_buf, m_length));
        while (!spi_xfer_done)
        {
            __WFE();
        }
				//unreliable transfer when no delay or it is lower 85us, reliable if delay are higher than 150us
				nrf_delay_us(85);
				
		memset(m_rx_buf, 0, m_length);
        spi_xfer_done = false;
        APP_ERROR_CHECK(nrf_drv_spi_transfer(&amp;amp;spi, m_tx_buf, m_length, m_rx_buf, m_length));
        while (!spi_xfer_done)
        {
            __WFE();
        }
        NRF_LOG_FLUSH();

        bsp_board_led_invert(BSP_BOARD_LED_0);
        nrf_delay_ms(2000);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;where I call a second transfer after the first one was already completed, and repeat it every 2 seconds&lt;/p&gt;
&lt;p&gt;getting unreliable transfers&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " height="412" src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/spibug.png" width="423" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;For my main application, I am not allowed to use delays between each transfer because I am calling the transfers from an IRQ context where I try to exit as fast as possible&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: best practices to nrf_drv_spi_transfer sequentially</title><link>https://devzone.nordicsemi.com/thread/176818?ContentTypeID=1</link><pubDate>Mon, 18 Mar 2019 20:28:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5e0d2224-e450-4b4c-8be9-f7e8b5c15f8f</guid><dc:creator>MeliodasD</dc:creator><description>&lt;p&gt;Hi Kenneth, when I am sending any message without any delay after called nrf_drv_spi_transfer() I have 2 scenarios, one where the SPI slave is not able to process&amp;nbsp;it, and the 2nd scenario where I got the corrupted data in the Slave (usually the last two bytes),&amp;nbsp;&lt;/p&gt;
&lt;p&gt;with a delay or not delays added to the code, I am always making sure not transfers are in progress waiting for the flag&amp;nbsp;transfer = 0 (it is cleared on the SPI handle after a transfer is done on the code above) and I check that flag before call nrf_drv_spi_transfer(), but it is very suspicious that transfers work fine only when a delay is added between each&amp;nbsp;&lt;span&gt;nrf_drv_spi_transfer()&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: best practices to nrf_drv_spi_transfer sequentially</title><link>https://devzone.nordicsemi.com/thread/176644?ContentTypeID=1</link><pubDate>Mon, 18 Mar 2019 09:53:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a58b9cb8-990c-41cf-8a81-235d3ef0fe74</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t see any obvious reason why you need a 1ms delay here on the master to not &amp;quot;overflow&amp;quot; the slave. May check that you have set:&lt;/p&gt;
&lt;p&gt;#define NRF_LOG_DEFERRED 1&lt;/p&gt;
&lt;p&gt;Since that will ensure you don&amp;#39;t have wait for each NRF_LOG() output to complete before it will resume code execution.&lt;/p&gt;
&lt;p&gt;Other than that I think you will need to add some gpio toggling to check what in your code may take a ~1ms to execute.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt; Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>