<?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>Sending a single Byte over SPI</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/37565/sending-a-single-byte-over-spi</link><description>I&amp;#39;m working in SDK 14.2, and trying to send a single byte over SPI between two NRF5 boards using the SPI peripheral examples (1 master and 1 slave). However, SPI always seems to want to send at least 2 bytes at a time. 
 I see that the errata acknowledges</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 20 Jul 2019 01:53:50 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/37565/sending-a-single-byte-over-spi" /><item><title>RE: Sending a single Byte over SPI</title><link>https://devzone.nordicsemi.com/thread/199615?ContentTypeID=1</link><pubDate>Sat, 20 Jul 2019 01:53:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e3bb248e-7425-496c-9009-90e63a26603d</guid><dc:creator>Yasser</dc:creator><description>&lt;p&gt;Hi Eric,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I am using SDK 15. Need to send a single byte - address of the register. Nothing to read in the first transfer. Then send another byte &amp;quot;0&amp;quot; to read the data. I am using your approach of setting 0 for rx buffer len. But doesn&amp;#39;t work. Did you change the driver as suggested by&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;div class="author"&gt;
&lt;div class="meta"&gt;&lt;span class="user-name"&gt;&lt;span class="ui-userpresence ui-tip "&gt;Offline&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a class="internal-link view-user-profile" href="https://devzone.nordicsemi.com/members/knisbet_4000_metrocast.net"&gt;knisbet&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;a class="internal-link view-post navigable" href="https://devzone.nordicsemi.com/f/nordic-q-a/11438/problems-implementing-workaround-to-get-nrf52-to-send-an-octet-one-byte-through-spi/43153#43153"&gt;&lt;span class="ui-agodate ui-tip "&gt;over 3 years ago&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="content full threaded-reply-content user-defined-markup"&gt;
&lt;div class="content"&gt;
&lt;p&gt;This method did not work for me using SDK11. Nordic provided the following fix. The SDK drivers is not designed for this workaround.&lt;/p&gt;
&lt;p&gt;The stop event was not handled. In srf_drv_spi.c replace irq_handler_spim at line 557 with the below&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/11438/problems-implementing-workaround-to-get-nrf52-to-send-an-octet-one-byte-through-spi/43155?focus=true"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/11438/problems-implementing-workaround-to-get-nrf52-to-send-an-octet-one-byte-through-spi/43155?focus=true&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;This is my code:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;int main(void)
{
    bsp_board_init(BSP_INIT_LEDS);

    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    NRF_LOG_DEFAULT_BACKENDS_INIT();

    nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
    spi_config.ss_pin   = NRF_DRV_SPI_PIN_NOT_USED;
    spi_config.miso_pin = 7;
    spi_config.mosi_pin = 15;
    spi_config.sck_pin  = 12;
    APP_ERROR_CHECK(nrf_drv_spi_init(&amp;amp;spi, &amp;amp;spi_config, spi_event_handler, NULL));

    SEGGER_RTT_printf(0,&amp;quot;SPI example started.&amp;quot;);
    

    while (1)
    {
        // Reset rx buffer and transfer done flag
        memset(m_rx_buf, 0, 1);
        spi_xfer_done = false;

        ret_code_t err_code;


        m_tx_buf = 0xAE;

        nrf_gpio_pin_clear(16);
        err_code = nrf_drv_spi_transfer(&amp;amp;spi, m_tx_buf, 1, m_rx_buf, 0);

        m_tx_buf = 0x00;
        err_code = nrf_drv_spi_transfer(&amp;amp;spi, m_tx_buf, 1, m_rx_buf, 1);

        APP_ERROR_CHECK(err_code);

        nrf_gpio_pin_set(16);
        SEGGER_RTT_printf(0,&amp;quot;SPI 1.&amp;quot;);
        while (!spi_xfer_done)
        {
            __WFE();
        }

        SEGGER_RTT_printf(0,&amp;quot;SPI 2.&amp;quot;);    
        SEGGER_RTT_printf(0, &amp;quot;%d Should be = 51\n&amp;quot;, m_rx_buf);
        NRF_LOG_FLUSH();

        bsp_board_led_invert(BSP_BOARD_LED_0);
        nrf_delay_ms(200);
    }
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I am getting stuck in&amp;nbsp;while (!spi_xfer_done)&lt;br /&gt; {&lt;br /&gt; __WFE();&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;I am trying to use SPI with ADS1293 with nRF52832. Here&amp;#39;s arduino code that works:&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;byte readRegister(byte reg) {
  byte data;
  reg |= 1 &amp;lt;&amp;lt; 7;
  digitalWrite(pin_SS, LOW);
  SPI.transfer(reg);
  data = SPI.transfer(0);
  digitalWrite(pin_SS, HIGH);
  return data;
}&lt;/pre&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sending a single Byte over SPI</title><link>https://devzone.nordicsemi.com/thread/161768?ContentTypeID=1</link><pubDate>Thu, 13 Dec 2018 21:49:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2aee1485-4831-4d91-89fa-49d43c6e7678</guid><dc:creator>Eric</dc:creator><description>&lt;p&gt;The best solution I found was given by joe.ker:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/11438/problems-implementing-workaround-to-get-nrf52-to-send-an-octet-one-byte-through-spi/43155?focus=true"&gt;devzone.nordicsemi.com/.../43155&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I can confirm this works in SDK15.2 (Sept-2018).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;
&lt;/code&gt;&lt;/p&gt;
&lt;div class="content-scrollable-wrapper content-scrollable-wrapper-scrolled"&gt;&lt;/div&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;if (len == 1)
{
    err_code = nrf_drv_spi_transfer(&amp;amp;m_spi_master, m_buffer_tx_spi, len, m_buffer_rx_spi, 0);
}
else
{
    err_code = nrf_drv_spi_transfer(&amp;amp;m_spi_master, m_buffer_tx_spi, len, m_buffer_rx_spi, len);
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sending a single Byte over SPI</title><link>https://devzone.nordicsemi.com/thread/144742?ContentTypeID=1</link><pubDate>Fri, 17 Aug 2018 13:45:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:da25068b-80f5-431a-abb7-e9dd7e8f646d</guid><dc:creator>Martin Lesund</dc:creator><description>&lt;p&gt;Hi Scott,&lt;/p&gt;
&lt;p&gt;When working with SPI I highly recommend that you use a logic analyzer (ex. &lt;a href="https://www.saleae.com/"&gt;saleae&lt;/a&gt;) to check what is going on in the different signal lines.&lt;/p&gt;
&lt;p&gt;When it comes to the errata 58 here is a &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/11438/problems-implementing-workaround-to-get-nrf52-to-send-an-octet-one-byte-through-spi/43140#43140"&gt;thread&lt;/a&gt; describing how to use it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>