AnsweredAssumed Answered

SPI comms between 2 MCUs

Question asked by Oliver Hobson on May 14, 2013
Latest reply on May 14, 2013 by Oliver Hobson

Hi,

 

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.

 

// For the Master MCU  void laserComm(char Data[]) {    if (Data[0] == 'X')PTCD_PTCD6 = 0; //Pull low to select correct slave   if (Data[0] == 'Y')PTCD_PTCD5 = 0; //Pull low to select correct slave   if (Data[0] == 'Z')PTCD_PTCD4 = 0; //Pull low to select correct slave    for(laserCommCount=0; laserCommCount <= dataSize ; laserCommCount++)        SPIdataIn[laserCommCount] = SPItransfer(Data[laserCommCount]);    PTCD_PTCD6 = 1; // Pull high after data transfer   PTCD_PTCD5 = 1;   PTCD_PTCD4 = 1; }  byte SPItransfer (byte val) {   // First send, then receive   while(!SPIS_SPTEF);   SPID = val;   while(!SPIS_SPRF);   return SPID; }  // For the slave MCU interrupt 15 void receiveSPI (void) {         SPIdataIn[SPIReceiveIndex] = SPItransfer(Packet1[SPIReceiveIndex]);         if (SPIReceiveIndex == dataSize)         {             SPIdataReceived = 1;             // Indicate the data has been received                  SPIReceiveIndex = 0; // Reset receive index             }        else SPIReceiveIndex++; }

 

all the data is an array of chars.

 

Thanks!

 

Outcomes