<?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>Difference between nrf_spim and spi examples in peripheral folder and purpose of __WFEwhile (!spi_xfer_done)
    {
        __WFE();
    }</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/60059/difference-between-nrf_spim-and-spi-examples-in-peripheral-folder-and-purpose-of-__wfewhile-spi_xfer_done-__wfe</link><description>I am basically wondering what the difference between these two examples in the SDK are? 
 Also, I see in both cases after the spi_transfer is called there is the following piece of code 
 
 I am just wondering what the purpose of it is and if it is necessary</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 14 Apr 2020 13:15:15 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/60059/difference-between-nrf_spim-and-spi-examples-in-peripheral-folder-and-purpose-of-__wfewhile-spi_xfer_done-__wfe" /><item><title>RE: Difference between nrf_spim and spi examples in peripheral folder and purpose of __WFEwhile (!spi_xfer_done)
    {
        __WFE();
    }</title><link>https://devzone.nordicsemi.com/thread/244448?ContentTypeID=1</link><pubDate>Tue, 14 Apr 2020 13:15:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:92a25cd6-2eef-4c91-91bd-32220b008399</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Michael&lt;/p&gt;
&lt;p&gt;The SPI examples are made for the older SPI master peripheral that didn&amp;#39;t support DMA, which was present in the nRF51 and nRF52 series.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The SPIM module is the SPI master with DMA support, which was added in the nRF52 series.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For the nRF52 I would recommend sticking to the SPIM examples, to leverage the new and improved hardware.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The&amp;nbsp;while (!spi_xfer_done)&amp;nbsp;{&amp;nbsp; __WFE(); } is essentially a way to make a non-blocking driver blocking, by entering into a sleep loop as long as the SPI transfer is ongoing. The call to __WFE() puts the CPU in system ON sleep mode, to avoid wasting energy by running in a loop.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Still, if you plan to do a lot of SPI communication I would suggest going for a more event driven approach where you use the SPI callback to schedule new transactions, rather than waiting for the SPI transaction to finish in a loop.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>