<?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>SPI read and write multiple bytes of varying lengths with MCP2515</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/52089/spi-read-and-write-multiple-bytes-of-varying-lengths-with-mcp2515</link><description>Hi, 
 Recently I was able to get a single read and write SPI operation to work properly with a custom nRF52832 (BL652) with SPI connection to MCP2515 (CAN SPI) using the nrf_drv_spi.c/h. (Solved through the following: https://devzone.nordicsemi.com/f</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 16 Sep 2019 21:57:33 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/52089/spi-read-and-write-multiple-bytes-of-varying-lengths-with-mcp2515" /><item><title>RE: SPI read and write multiple bytes of varying lengths with MCP2515</title><link>https://devzone.nordicsemi.com/thread/209951?ContentTypeID=1</link><pubDate>Mon, 16 Sep 2019 21:57:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b8a2cdd6-8052-4728-aab5-c8a18321d9c3</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Try correcting this error and see if that helps:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void mcp2515_spi_transfer(uint8_t p_tx_data, uint8_t p_rx_data, const uint16_t len)
{
    // Reset rx buffer and transfer done flag
    memset(&amp;amp;p_rx_data, 0, len);
    
    NRF_LOG_INFO(&amp;quot;tx data %x\n&amp;quot;, p_tx_data);

    APP_ERROR_CHECK(nrf_drv_spi_transfer(&amp;amp;can_spi, &amp;amp;p_tx_data, len, &amp;amp;p_rx_data, len));&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Should be&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void mcp2515_spi_transfer(uint8_t *p_tx_data, uint8_t *p_rx_data, const uint16_t len)
{
    // Reset rx buffer and transfer done flag
    memset(p_rx_data, 0, len);
    
    NRF_LOG_INFO(&amp;quot;tx data %x\n&amp;quot;, p_tx_data);

    APP_ERROR_CHECK(nrf_drv_spi_transfer(&amp;amp;can_spi, p_tx_data, len, p_rx_data, len));&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;In the first case you are using the address of a byte parameter on the stack, not the address of the buffers you require.&lt;/p&gt;
&lt;p&gt;You might also try increasing the drive of the SCK output pin to H0H1, just until you have everything working. This must be done after initialising the SPI which sets that output pin to S0S1. If the CAN chip is off-board maybe long leads or capacitance issues are corrupting transfers, although unlikely at 250kHz&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI read and write multiple bytes of varying lengths with MCP2515</title><link>https://devzone.nordicsemi.com/thread/209942?ContentTypeID=1</link><pubDate>Mon, 16 Sep 2019 20:23:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bac4127b-ab81-43e7-ac66-81128524f74f</guid><dc:creator>BendaEng</dc:creator><description>&lt;p&gt;I have tried to analyze the SPI lines using an SDS 1104X-E scope. I don&amp;#39;t see any data coming out, only 0x00 on the MISO line. For the first section however (initialization of MCP2515) I get the following readout (This is based on the attached main.c and mcp_can.c/h and mcp_can_dfs.h which I&amp;#39;ve modified):&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;info&amp;gt; app: Template example started.
&amp;lt;info&amp;gt; app: Fast advertising.
&amp;lt;info&amp;gt; app: CAN SPI example started.
&amp;lt;info&amp;gt; app: Start

&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Enter setting mode success 

&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: set rate success!!

&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Enter Normal Mode Success!!

&amp;lt;info&amp;gt; app: CAN initialization ok

&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Data Received 0 0x0
&amp;lt;info&amp;gt; app: Data Received 1 0x0
&amp;lt;info&amp;gt; app: Data Received 2 0x0
&amp;lt;info&amp;gt; app: Data Received 3 0x3
&amp;lt;info&amp;gt; app: Data Received 4 0x3
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Data Received 0 0x0
&amp;lt;info&amp;gt; app: Data Received 1 0x0
&amp;lt;info&amp;gt; app: Data Received 2 0x0
&amp;lt;info&amp;gt; app: Data Received 3 0x3
&amp;lt;info&amp;gt; app: Data Received 4 0x3
&amp;lt;info&amp;gt; app: Transfer completed.
&amp;lt;info&amp;gt; app: Data Received 0 0x0
&amp;lt;info&amp;gt; app: Data Received 1 0x0
&amp;lt;info&amp;gt; app: Data Received 2 0x0
&amp;lt;info&amp;gt; app: Data Received 3 0x3
&amp;lt;info&amp;gt; app: Data Received 4 0x3
&amp;lt;info&amp;gt; app: Transfer completed.


...//This repeats&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/2474.mcp_5F00_can.c"&gt;devzone.nordicsemi.com/.../2474.mcp_5F00_can.c&lt;/a&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/mcp_5F00_can.h"&gt;devzone.nordicsemi.com/.../mcp_5F00_can.h&lt;/a&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/mcp_5F00_can_5F00_dfs.h"&gt;devzone.nordicsemi.com/.../mcp_5F00_can_5F00_dfs.h&lt;/a&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/2867.main.c"&gt;devzone.nordicsemi.com/.../2867.main.c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I think I&amp;#39;m getting through the initialization because the setup is checking if the received is 0x00, which is what I&amp;#39;m only getting. What could be a cause of no response from the MCP2515 do you think?&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI read and write multiple bytes of varying lengths with MCP2515</title><link>https://devzone.nordicsemi.com/thread/209805?ContentTypeID=1</link><pubDate>Mon, 16 Sep 2019 11:38:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:39575dae-f9ab-46d7-bf58-fb1cab01b98f</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Have you tried to analyze the SPI lines with a logic analyzer? Is there any data coming from the device? Or is it flat at GND?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI read and write multiple bytes of varying lengths with MCP2515</title><link>https://devzone.nordicsemi.com/thread/209492?ContentTypeID=1</link><pubDate>Thu, 12 Sep 2019 18:32:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0ab9ed21-3f21-4232-85f8-3dfee6531aaf</guid><dc:creator>BendaEng</dc:creator><description>&lt;p&gt;Well I had been doing this. But adding 2 to the length (2+5) returns all zeros (0x0 for all).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// Enter main loop.
    for (;;)
    {
        uint8_t values[5]; 
        mcp2515_readRegisterS(MCP_READ_STATUS, values, 5);
        
        for(uint8_t i = 0; i&amp;lt;5; i++)
          {
            NRF_LOG_INFO(&amp;quot;Data Received %d 0x%x&amp;quot;, i, values[i]);
          }
          nrf_delay_ms(10);

        idle_state_handle();
    }&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI read and write multiple bytes of varying lengths with MCP2515</title><link>https://devzone.nordicsemi.com/thread/209491?ContentTypeID=1</link><pubDate>Thu, 12 Sep 2019 18:12:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:08f24c82-0412-4222-a9bd-19d1a1d31a51</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;So is this the call:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint8_t someBuffer[5];
mcp2515_readRegisterS(0, someBuffer, 2+5);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI read and write multiple bytes of varying lengths with MCP2515</title><link>https://devzone.nordicsemi.com/thread/209488?ContentTypeID=1</link><pubDate>Thu, 12 Sep 2019 17:51:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8f17b748-c848-4996-a798-24b42e8a7b96</guid><dc:creator>BendaEng</dc:creator><description>&lt;p&gt;Ok, I guess what I was thinking in that last code snippet was that regardless of when the instruction &amp;quot;MCP_READ_STATUS&amp;quot; was sent (either right after the MCP_READ or as the only byte sent) the outcome was the same.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*********************************************************************************************************
** Function name:           mcp2515_readRegisterS
** Descriptions:            read registerS
*********************************************************************************************************/

void mcp2515_readRegisterS(const uint8_t address, uint8_t values[], const uint8_t n)
{
    uint8_t i; 
      
    //uint8_t m_tx_buf[] = {MCP_READ, address};
    uint8_t m_tx_buf[] = {address};
    uint8_t m_rx_buf[n]; 
    uint8_t m_tx_length = sizeof(m_tx_buf);
    uint8_t m_rx_length = sizeof(m_rx_buf);

    memset(m_rx_buf, 0, m_rx_length);
        
    spi_xfer_done = false;

    APP_ERROR_CHECK(nrf_drv_spi_transfer(&amp;amp;can_spi, m_tx_buf, m_tx_length, m_rx_buf, m_rx_length));

     while (!spi_xfer_done)
        {
            __WFE();
        }  
  
    // mcp2515 has auto-increment of address-pointer
    for (i=0; i&amp;lt;n-2 &amp;amp;&amp;amp; i&amp;lt;CAN_MAX_CHAR_IN_MESSAGE-2; i++)
    {
      values[i] = m_rx_buf[i+2];
    }
    return; 

}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Yielded:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;lt;info&amp;gt; app: Data Received 0 0x0&lt;br /&gt;&amp;lt;info&amp;gt; app: Data Received 1 0x0&lt;br /&gt;&amp;lt;info&amp;gt; app: Data Received 2 0x0&lt;br /&gt;&amp;lt;info&amp;gt; app: Data Received 3 0x3&lt;br /&gt;&amp;lt;info&amp;gt; app: Data Received 4 0x3&lt;br /&gt;&amp;lt;info&amp;gt; app: Transfer completed.&lt;/p&gt;
&lt;p&gt;And,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*********************************************************************************************************
** Function name:           mcp2515_readRegisterS
** Descriptions:            read registerS
*********************************************************************************************************/

void mcp2515_readRegisterS(const uint8_t address, uint8_t values[], const uint8_t n)
{
    uint8_t i; 
      
    uint8_t m_tx_buf[] = {MCP_READ, address};
    //uint8_t m_tx_buf[] = {address};
    uint8_t m_rx_buf[n]; 
    uint8_t m_tx_length = sizeof(m_tx_buf);
    uint8_t m_rx_length = sizeof(m_rx_buf);

    memset(m_rx_buf, 0, m_rx_length);
        
    spi_xfer_done = false;

    APP_ERROR_CHECK(nrf_drv_spi_transfer(&amp;amp;can_spi, m_tx_buf, m_tx_length, m_rx_buf, m_rx_length));

     while (!spi_xfer_done)
        {
            __WFE();
        }  
  
    // mcp2515 has auto-increment of address-pointer
    for (i=0; i&amp;lt;n-2 &amp;amp;&amp;amp; i&amp;lt;CAN_MAX_CHAR_IN_MESSAGE-2; i++)
    {
      values[i] = m_rx_buf[i+2];
    }
    return; 

}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Yielded:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;lt;info&amp;gt; app: Data Received 0 0x0&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;lt;info&amp;gt; app: Data Received 1 0x0&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;lt;info&amp;gt; app: Data Received 2 0x0&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;lt;info&amp;gt; app: Data Received 3 0x3&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;lt;info&amp;gt; app: Data Received 4 0x3&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;lt;info&amp;gt; app: Transfer completed.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If I send a MCP_READ_STATUS instruction I believe I should be receiving the following (since it outputs the same data each byte read).&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;lt;info&amp;gt; app: Data Received 0 0x3&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;lt;info&amp;gt; app: Data Received 1 0x3&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;lt;info&amp;gt; app: Data Received 2 0x3&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;lt;info&amp;gt; app: Data Received 3 0x3&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;lt;info&amp;gt; app: Data Received 4 0x3&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;lt;info&amp;gt; app: Transfer completed.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;It looks like the first three buffer locations of m_rx_buf (i.e. m_rx_buf[2], m_rx_buf[3], and m_rx_buf[4] are getting overwritten, or I&amp;#39;m not looking in the proper location for the received data.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI read and write multiple bytes of varying lengths with MCP2515</title><link>https://devzone.nordicsemi.com/thread/209487?ContentTypeID=1</link><pubDate>Thu, 12 Sep 2019 17:15:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:199485e3-fba0-424a-830f-b887b3c23bee</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;That&amp;#39;s a step backwards - tx_length must be 2 not 1, as the command byte &lt;em&gt;MCP_READ&lt;/em&gt; is not being sent in that latest code snippet; the original m_tx_buf was correct:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    uint8_t m_tx_buf[] = {MCP_READ, address};
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI read and write multiple bytes of varying lengths with MCP2515</title><link>https://devzone.nordicsemi.com/thread/209486?ContentTypeID=1</link><pubDate>Thu, 12 Sep 2019 16:58:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:38229548-d1fc-4c3c-b495-1cabcd75db63</guid><dc:creator>BendaEng</dc:creator><description>&lt;p&gt;That was part of it, the return was misplaced. When ran the data received is the following (for READ_STATUS):&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;lt;info&amp;gt; app: Data Received 0 0x0&lt;br /&gt;&amp;lt;info&amp;gt; app: Data Received 1 0x0&lt;br /&gt;&amp;lt;info&amp;gt; app: Data Received 2 0x0&lt;br /&gt;&amp;lt;info&amp;gt; app: Data Received 3 0x3&lt;br /&gt;&amp;lt;info&amp;gt; app: Data Received 4 0x3&lt;br /&gt;&amp;lt;info&amp;gt; app: Transfer completed.&lt;/p&gt;
&lt;p&gt;It seems like the sizeof() is being handled properly. I changed the values to how much I want to read and it doesn&amp;#39;t make a difference.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint8_t m_tx_buf[] = {address};
    uint8_t m_rx_buf[n]; 
    uint8_t m_tx_length = 1; //sizeof(m_tx_buf);
    uint8_t m_rx_length = 5; //sizeof(m_rx_buf);

    memset(m_rx_buf, 0, m_rx_length);
        
    spi_xfer_done = false;

    APP_ERROR_CHECK(nrf_drv_spi_transfer(&amp;amp;can_spi, m_tx_buf, m_tx_length, m_rx_buf, m_rx_length));

     while (!spi_xfer_done)
        {
            __WFE();
        }  &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Another interesting thing to note: When I change the &amp;#39;2&amp;#39; to &amp;#39;3&amp;#39; in the for loop I get the following output (the 0x10 corresponds to what I received previously:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;lt;info&amp;gt; app: Data Received 0 0x0&lt;br /&gt;&amp;lt;info&amp;gt; app: Data Received 1 0x0&lt;br /&gt;&amp;lt;info&amp;gt; app: Data Received 2 0x10&lt;br /&gt;&amp;lt;info&amp;gt; app: Data Received 3 0x3&lt;br /&gt;&amp;lt;info&amp;gt; app: Data Received 4 0x3&lt;br /&gt;&amp;lt;info&amp;gt; app: Transfer completed.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;for (i=0; i&amp;lt;n-3 &amp;amp;&amp;amp; i&amp;lt;CAN_MAX_CHAR_IN_MESSAGE-3; i++)
    {
      //values[i] = spi_read();
      values[i] = m_rx_buf[i+3];
    }
    return;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI read and write multiple bytes of varying lengths with MCP2515</title><link>https://devzone.nordicsemi.com/thread/209485?ContentTypeID=1</link><pubDate>Thu, 12 Sep 2019 16:19:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cdef41d4-3386-4e5d-a4a6-96ad9ea6f635</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;I think READ and READ_RX_BUFFER both auto-increment starting at the supplied address, but READ_STATUS does not, it simply repeats the status byte for verification and error checking. I only had time for a quick look, and I see the return statement is misplaced which means you were looking at random data on the stack after the first byte:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;Code above:
    for (i=0; i&amp;lt;n-2 &amp;amp;&amp;amp; i&amp;lt;CAN_MAX_CHAR_IN_MESSAGE-2; i++)
    {
      return values[i] = m_rx_buf[i+2];
    }
Should be:
    for (i=0; i&amp;lt;n-2 &amp;amp;&amp;amp; i&amp;lt;CAN_MAX_CHAR_IN_MESSAGE-2; i++)
    {
      values[i] = m_rx_buf[i+2];
    }
    return;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I assume&amp;nbsp;MCP_READ is 0x03? Also I am not sure all compilers would handle &lt;em&gt;sizeof()&lt;/em&gt; correctly when used on a passed parameter but that could be easily verified with a breakpoint&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>