<?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>nRF52810 SPI and duration of CS after last byte transferred</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/45727/nrf52810-spi-and-duration-of-cs-after-last-byte-transferred</link><description>In my attempt of learning the nRF52 &amp;quot;eco system&amp;quot; (nRF52 DK, nRF15.3 SDK, SES and pca10040e project for nRF52810), I have combined the GATT_C, GPIO and SPI examples to make an application for streaming CAN data over BLE. CAN is a mcp2515 chip with SPI</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 09 Apr 2019 11:24:53 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/45727/nrf52810-spi-and-duration-of-cs-after-last-byte-transferred" /><item><title>RE: nRF52810 SPI and duration of CS after last byte transferred</title><link>https://devzone.nordicsemi.com/thread/181013?ContentTypeID=1</link><pubDate>Tue, 09 Apr 2019 11:24:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e1d444cc-8ec9-4fa6-83c1-4daa168f20c5</guid><dc:creator>Skols</dc:creator><description>&lt;p&gt;Ok. Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52810 SPI and duration of CS after last byte transferred</title><link>https://devzone.nordicsemi.com/thread/180733?ContentTypeID=1</link><pubDate>Mon, 08 Apr 2019 11:54:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0107e598-a116-48ef-a7dd-189e525376ec</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The SPIM peripheral in the nRF52810 does not implement chip select, so this is handled by the driver by controlling a GPIO pin. Looking at the implementation in nrfx (modules\nrfx\drivers\src\nrfx_spim.c) you can see that it is cleared by the&amp;nbsp;finish_transfer() function, which is called as the last thing when handling the&amp;nbsp;NRF_SPIM_EVENT_END. If you use on-deferred logging you might be able to save a bit of time by moving the call to finish_transfer()&amp;nbsp; before the log line, but other than that there is not much optimization to be done as far as I can see.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52810 SPI and duration of CS after last byte transferred</title><link>https://devzone.nordicsemi.com/thread/180109?ContentTypeID=1</link><pubDate>Wed, 03 Apr 2019 19:02:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ea1edd12-0f2a-4988-92b3-2db219cf94a3</guid><dc:creator>Skols</dc:creator><description>&lt;p&gt;Yes, tested that as well, but it had no impact. Can it be that the&amp;nbsp; __WFE need some time to&amp;nbsp;&amp;nbsp;discover that the bytes are transmitted... ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52810 SPI and duration of CS after last byte transferred</title><link>https://devzone.nordicsemi.com/thread/180104?ContentTypeID=1</link><pubDate>Wed, 03 Apr 2019 18:36:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:399effc5-a0a2-4f16-8139-ca152bae0de1</guid><dc:creator>Fred</dc:creator><description>&lt;p&gt;Did&amp;nbsp;you&amp;nbsp;try adding your mcp2515_unselect() in the spi_event_handler()? That&amp;#39;s effectively doing it in an ISR.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52810 SPI and duration of CS after last byte transferred</title><link>https://devzone.nordicsemi.com/thread/180100?ContentTypeID=1</link><pubDate>Wed, 03 Apr 2019 18:23:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b9ee50d5-1487-4514-8109-8a9cc8b02591</guid><dc:creator>Skols</dc:creator><description>&lt;p&gt;Thanks for the advice. I tested it, but it had little to no impact in my application&lt;/p&gt;
&lt;p&gt;I guess I also have to do some more clever stuff than only controlling&amp;nbsp; SS/CS myself?&lt;/p&gt;
&lt;p&gt;I have an spi_eventhandler():&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;void spi_event_handler(nrf_drv_spi_evt_t const * p_event,
                       void *                    p_context)
{
      spi_xfer_done = true;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;and typically my SPI functions looks like this:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;uint8_t mcp2515_readRegister( uint8_t address)                                                                     
{
    uint8_t ret;
    ret_code_t err_code;

    uint8_t m_tx_buf[] = {MCP_READ, address};
    uint8_t m_rx_buf[] = {0, 0, 0};

    //mcp2515_select();
    err_code = nrf_drv_spi_transfer(&amp;amp;spi, m_tx_buf, 2, m_rx_buf, 3);
    APP_ERROR_CHECK(err_code);
    
    while (!spi_xfer_done) { __WFE(); }
    spi_xfer_done = false;
    //mcp2515_unselect();

    return m_rx_buf[2];
}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;In the case of controlling CS/SS myself: The reason why it have little impact in my code is probably that before I can set CS high, I wait for __WFE, which triggers my SPI_eventhandler, which set the flag to terminate the wait loop.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;On other controllers I usually handle all these things in interrupt service routines (ISR), but I am not there yet that I know how to deal with ISRs on the nRF-platform using the SoftDevice for BLE...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52810 SPI and duration of CS after last byte transferred</title><link>https://devzone.nordicsemi.com/thread/180092?ContentTypeID=1</link><pubDate>Wed, 03 Apr 2019 16:56:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:807765e8-ce77-4dac-8b50-2a64a87c0a6a</guid><dc:creator>Fred</dc:creator><description>&lt;p&gt;For controlling the CS there are two options: either this is done automatically by SoftDevice or you could control the CS pin yourself. This can be done by setting the&amp;nbsp;ss_pin of the&amp;nbsp;nrf_drv_spi_config_t struct to NRF_DRV_SPI_PIN_NOT_USED. In my projects I always control the CS (or Slave Select as it is called here) myself.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>