<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>8-bit MicrocontrollersのトピックRe: SPI comms between 2 MCUs</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/SPI-comms-between-2-MCUs/m-p/237462#M19508</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In the slave code, I would have checked the SPRF and read the data, followed by stuffing of byte to be sent... something like this &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;OL class="dp-cpp" start="1" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; list-style-position: initial; list-style-image: initial; background-color: #ffffff; color: #5c5c5c; margin: 0 0 1px 45px !important;"&gt;&lt;LI&gt;&lt;SPAN style="font-style: inherit; font-family: helvetica, arial; color: black; background-color: inherit; font-size: 9pt !important;"&gt;byte SPItransfer_ForSlave (byte val)&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-style: inherit; font-family: helvetica, arial; color: black; background-color: inherit; font-size: 9pt !important;"&gt;{&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-style: inherit; font-family: helvetica, arial; color: black; background-color: inherit; font-size: 9pt !important;"&gt;&amp;nbsp; byte return_data;&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-style: inherit; font-family: helvetica, arial; color: black; background-color: inherit; font-size: 9pt !important;"&gt;&amp;nbsp; &lt;SPAN class="comment" style="font-style: inherit; color: #008200; background-color: inherit; font-size: 9pt !important;"&gt;// First receive, then keep the register updated with val&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-style: inherit; font-family: helvetica, arial; color: black; background-color: inherit; font-size: 9pt !important;"&gt;&lt;SPAN class="comment" style="font-style: inherit; color: #008200; background-color: inherit; font-size: 9pt !important;"&gt;&lt;SPAN style="color: #000000; font-family: helvetica, arial; font-size: 12px; background-color: #ffffff;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="keyword" style="font-family: helvetica, arial; font-style: inherit; color: #006699; font-size: 9pt !important;"&gt;while&lt;/SPAN&gt;&lt;SPAN style="color: #000000; font-family: helvetica, arial; font-style: inherit; font-size: 9pt !important;"&gt;(!SPIS_SPRF);&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style=": ; color: #000000; font-style: inherit; font-size: 9pt !important; background-color: inherit; font-family: helvetica, arial;"&gt;&amp;nbsp; &lt;SPAN style="color: #000000; font-family: helvetica, arial; font-size: 12px; background-color: #ffffff;"&gt;return_data&lt;/SPAN&gt; = &lt;SPAN style="color: #000000; font-family: helvetica, arial; font-size: 12px; background-color: #ffffff;"&gt;SPID&lt;/SPAN&gt;;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-style: inherit; font-family: helvetica, arial; color: black; background-color: inherit; font-size: 9pt !important;"&gt;&amp;nbsp; SPID = val;&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-style: inherit; font-family: helvetica, arial; color: black; background-color: inherit; font-size: 9pt !important;"&gt;&amp;nbsp; &lt;SPAN class="keyword" style="font-style: inherit; color: #006699; background-color: inherit; font-size: 9pt !important;"&gt;return&lt;/SPAN&gt;&lt;SPAN style="font-style: inherit; background-color: inherit; font-size: 9pt !important;"&gt; &lt;SPAN style="color: #000000; font-family: helvetica, arial; font-size: 12px; background-color: #ffffff;"&gt;return_data&lt;/SPAN&gt;;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-style: inherit; font-family: helvetica, arial; color: black; background-color: inherit; font-size: 9pt !important;"&gt;}&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 14 May 2013 11:34:21 GMT</pubDate>
    <dc:creator>yanam</dc:creator>
    <dc:date>2013-05-14T11:34:21Z</dc:date>
    <item>
      <title>SPI comms between 2 MCUs</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/SPI-comms-between-2-MCUs/m-p/237461#M19507</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am attempting to establish SPI communication between 2 GT16a MCUs, where one is the slave and the other the master. I am able to send data from the master to the slave, but am receiving rubbish when trying to get data sent from the slave to the master. Any idea as to what could be the problem. &lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="c++" name="code"&gt;// For the Master MCU&amp;nbsp; void laserComm(char Data[]) {&amp;nbsp; &amp;nbsp; if (Data[0] == 'X')PTCD_PTCD6 = 0; //Pull low to select correct slave &amp;nbsp; if (Data[0] == 'Y')PTCD_PTCD5 = 0; //Pull low to select correct slave &amp;nbsp; if (Data[0] == 'Z')PTCD_PTCD4 = 0; //Pull low to select correct slave&amp;nbsp; &amp;nbsp; for(laserCommCount=0; laserCommCount &amp;lt;= dataSize ; laserCommCount++) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SPIdataIn[laserCommCount] = SPItransfer(Data[laserCommCount]);&amp;nbsp; &amp;nbsp; PTCD_PTCD6 = 1; // Pull high after data transfer &amp;nbsp; PTCD_PTCD5 = 1; &amp;nbsp; PTCD_PTCD4 = 1; }&amp;nbsp; byte SPItransfer (byte val) { &amp;nbsp; // First send, then receive &amp;nbsp; while(!SPIS_SPTEF); &amp;nbsp; SPID = val; &amp;nbsp; while(!SPIS_SPRF); &amp;nbsp; return SPID; }&amp;nbsp; // For the slave MCU interrupt 15 void receiveSPI (void) {&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SPIdataIn[SPIReceiveIndex] = SPItransfer(Packet1[SPIReceiveIndex]);&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (SPIReceiveIndex == dataSize)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SPIdataReceived = 1;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Indicate the data has been received&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SPIReceiveIndex = 0; // Reset receive index&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else SPIReceiveIndex++; }&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;all the data is an array of chars.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="c++" name="code"&gt;&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 May 2013 10:50:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/SPI-comms-between-2-MCUs/m-p/237461#M19507</guid>
      <dc:creator>woohoo</dc:creator>
      <dc:date>2013-05-14T10:50:28Z</dc:date>
    </item>
    <item>
      <title>Re: SPI comms between 2 MCUs</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/SPI-comms-between-2-MCUs/m-p/237462#M19508</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In the slave code, I would have checked the SPRF and read the data, followed by stuffing of byte to be sent... something like this &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;OL class="dp-cpp" start="1" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; list-style-position: initial; list-style-image: initial; background-color: #ffffff; color: #5c5c5c; margin: 0 0 1px 45px !important;"&gt;&lt;LI&gt;&lt;SPAN style="font-style: inherit; font-family: helvetica, arial; color: black; background-color: inherit; font-size: 9pt !important;"&gt;byte SPItransfer_ForSlave (byte val)&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-style: inherit; font-family: helvetica, arial; color: black; background-color: inherit; font-size: 9pt !important;"&gt;{&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-style: inherit; font-family: helvetica, arial; color: black; background-color: inherit; font-size: 9pt !important;"&gt;&amp;nbsp; byte return_data;&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-style: inherit; font-family: helvetica, arial; color: black; background-color: inherit; font-size: 9pt !important;"&gt;&amp;nbsp; &lt;SPAN class="comment" style="font-style: inherit; color: #008200; background-color: inherit; font-size: 9pt !important;"&gt;// First receive, then keep the register updated with val&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-style: inherit; font-family: helvetica, arial; color: black; background-color: inherit; font-size: 9pt !important;"&gt;&lt;SPAN class="comment" style="font-style: inherit; color: #008200; background-color: inherit; font-size: 9pt !important;"&gt;&lt;SPAN style="color: #000000; font-family: helvetica, arial; font-size: 12px; background-color: #ffffff;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="keyword" style="font-family: helvetica, arial; font-style: inherit; color: #006699; font-size: 9pt !important;"&gt;while&lt;/SPAN&gt;&lt;SPAN style="color: #000000; font-family: helvetica, arial; font-style: inherit; font-size: 9pt !important;"&gt;(!SPIS_SPRF);&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style=": ; color: #000000; font-style: inherit; font-size: 9pt !important; background-color: inherit; font-family: helvetica, arial;"&gt;&amp;nbsp; &lt;SPAN style="color: #000000; font-family: helvetica, arial; font-size: 12px; background-color: #ffffff;"&gt;return_data&lt;/SPAN&gt; = &lt;SPAN style="color: #000000; font-family: helvetica, arial; font-size: 12px; background-color: #ffffff;"&gt;SPID&lt;/SPAN&gt;;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-style: inherit; font-family: helvetica, arial; color: black; background-color: inherit; font-size: 9pt !important;"&gt;&amp;nbsp; SPID = val;&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-style: inherit; font-family: helvetica, arial; color: black; background-color: inherit; font-size: 9pt !important;"&gt;&amp;nbsp; &lt;SPAN class="keyword" style="font-style: inherit; color: #006699; background-color: inherit; font-size: 9pt !important;"&gt;return&lt;/SPAN&gt;&lt;SPAN style="font-style: inherit; background-color: inherit; font-size: 9pt !important;"&gt; &lt;SPAN style="color: #000000; font-family: helvetica, arial; font-size: 12px; background-color: #ffffff;"&gt;return_data&lt;/SPAN&gt;;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-style: inherit; font-family: helvetica, arial; color: black; background-color: inherit; font-size: 9pt !important;"&gt;}&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 May 2013 11:34:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/SPI-comms-between-2-MCUs/m-p/237462#M19508</guid>
      <dc:creator>yanam</dc:creator>
      <dc:date>2013-05-14T11:34:21Z</dc:date>
    </item>
    <item>
      <title>Re: SPI comms between 2 MCUs</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/SPI-comms-between-2-MCUs/m-p/237463#M19509</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As has already been mentioned, the SPItransfer() function is unsuited to slave use, and particularly so when using an interrupt for the slave process.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Any data to be returned by the slave needs to be pre-loaded to the slave buffer prior to SS from the master becoming active.&amp;nbsp; This data will then be shifted out to the master, as the next byte from the master is shifted in by the slave.&lt;/LI&gt;&lt;LI&gt;It is also possible to make use of the double buffering capability of the SPI module, where the first two return bytes would be preloaded to the buffer.&amp;nbsp; In this instance, it would not matter whether the new return data were loaded to the buffer prior to, or following the processing of the received byte, within the ISR.&lt;/LI&gt;&lt;LI&gt;When appropriately using the SPI interrupt for the slave end, the ISR should handle only a single byte at a time, and then exit.&lt;/LI&gt;&lt;LI&gt;The send process by the master may need to be suitably "paced" so that there is sufficient time for the slave ISR to complete execution, prior to the next byte being sent.&amp;nbsp; This will also need to take into account the processing of any other interrupts that may be enabled within the slave.&lt;/LI&gt;&lt;LI&gt;The master may also need to send an extra dummy byte so that the final slave byte can be returned from the SPI buffer.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;// Global variables:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;byte SPIdataIn[BUF_SIZE];&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;byte Packet1[BUF_SIZE];&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;byte dataSize;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;byte SPIdataReceived;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;static byte *Recv_buf;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;static byte *Send_buf;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;static byte byte_count;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; // Initialise pointers&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; Recv_buf = SPIdataIn;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; Send_buf = Packet1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; byte_count = 0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; SPIdataReceived = 0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;interrupt 15&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;void receiveSPI (void)&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;{&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; (void)SPIS;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Part of flag clearing&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; *Recv_buf++ = SPID;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Receive current byte&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; SPID = *Send_buf++;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Load next byte to buffer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; byte_count++;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; if (byte_count == dataSize)&amp;nbsp; {&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SPIdataReceived = 1; // Flag data received&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; byte_count = 0;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Reset counter&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; } &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 May 2013 13:54:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/SPI-comms-between-2-MCUs/m-p/237463#M19509</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2013-05-14T13:54:28Z</dc:date>
    </item>
    <item>
      <title>Re: SPI comms between 2 MCUs</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/SPI-comms-between-2-MCUs/m-p/237464#M19510</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the reply.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I just want to confirm that my code for the master to receive is valid, also is shown my modified code for the slave.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13685511340879390" jivemacro_uid="_13685511340879390" modifiedtitle="true"&gt;
&lt;P&gt;// Master&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;byte SPItransfer (byte val)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; // First send, then receive&lt;/P&gt;
&lt;P&gt;&amp;nbsp; while(!SPIS_SPTEF);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; SPID = val;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; while(!SPIS_SPRF);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; return SPID;&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;/////////////////////////////////////////////////////////////////////////////////////&lt;/P&gt;
&lt;P&gt;//Master&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;void laserComm(char Data[])&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if (Data[0] == 'X')PTCD_PTCD6 = 0; //Pull low to select correct slave&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if (Data[0] == 'Y')PTCD_PTCD5 = 0; //Pull low to select correct slave&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if (Data[0] == 'Z')PTCD_PTCD4 = 0; //Pull low to select correct slave&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; for(laserCommCount=0; laserCommCount &amp;lt;= dataSize ; laserCommCount++)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; SPIdataIn[laserCommCount] = SPItransfer(Data[laserCommCount]);&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; PTCD_PTCD6 = 1; // Pull high after data transfer&lt;/P&gt;
&lt;P&gt;&amp;nbsp; PTCD_PTCD5 = 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; PTCD_PTCD4 = 1;&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;/////////////////////////////////////////////////////////////////////////////////////&lt;/P&gt;
&lt;P&gt;//Slave receive function&lt;/P&gt;
&lt;P&gt;interrupt 15&amp;nbsp; // SPI receive interrupt&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;void receiveSPI (void)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; (void)SPIS; // Clear flags&lt;/P&gt;
&lt;P&gt;&amp;nbsp; SPIdataIn[SPIReceiveIndex] = SPID; // Receive byte&lt;/P&gt;
&lt;P&gt;&amp;nbsp; SPID = Packet1[SPIReceiveIndex]; // Load byte to send&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if (SPIReceiveIndex == dataSize) &lt;/P&gt;
&lt;P&gt;&amp;nbsp; {&lt;/P&gt;
&lt;P&gt;&amp;nbsp; SPIdataReceived = 1;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Indicate the data has been received&lt;/P&gt;
&lt;P&gt;&amp;nbsp; SPIReceiveIndex = 0; // Reset receive index&lt;/P&gt;
&lt;P&gt;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp; else SPIReceiveIndex++;&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also I still don't seem to be receiving the data I expect. Are there any timing considerations?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_text_macro _jivemacro_uid_13685511487169996 jive_macro_code" jivemacro_uid="_13685511487169996"&gt;
&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 May 2013 17:05:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/SPI-comms-between-2-MCUs/m-p/237464#M19510</guid>
      <dc:creator>woohoo</dc:creator>
      <dc:date>2013-05-14T17:05:02Z</dc:date>
    </item>
  </channel>
</rss>

