AnsweredAssumed Answered

GT16A SPI

Question asked by Oliver Hobson on Nov 8, 2012
Latest reply on Dec 17, 2012 by Monica Arvizu

Hi,

 

I am trying to get two GT16A MCUs to communicate via SPI, however I am not succeeding. The master is configured as shown below(SPI_Initialise), with the data sending being done in the laserComm function where Data[] is an array of unsigned char. Finally, the slave is configured as initSPI shows with the receiving done in the receiveSPI function. Any help would be appreciated!

 

void SPI_Initialise (void){      SPIBR = 0x00; // SPI baud rate = 9.437184MHz    SPIC1_SPIE  = 1;   SPIC1_SPE   = 1;   SPIC1_SPTIE = 0;    SPIC1_MSTR  = 1;   SPIC1_CPOL  = 0;   SPIC1_CPHA  = 1;   SPIC1_SSOE  = 0;   SPIC1_LSBFE = 0;     //SPIC2 = 0x00; // SPI control register 2 setup   SPIC2_MODFEN = 0;   SPIC2_BIDIROE = 0;   SPIC2_SPISWAI = 0;    SPIC2_SPC0 = 0; } void laserComm(char Data[]){   int i;   PTCD_PTCD6 = 0; //Pull low to select slave   PTCD_PTCD5 = 0; //Pull low to select slave   PTCD_PTCD4 = 0; //Pull low to select slave   PTCD_PTCD3 = 0; //Pull low to select slave    for(i = 0; i<=dataSize; i++){//send data   while(!SPIS_SPTEF)   SPID = Data[i++];   }   PTCD_PTCD6 = 1;   PTCD_PTCD5 = 1;   PTCD_PTCD4 = 1;   PTCD_PTCD3 = 1; }  ///////// SLAVE //////////////// void initSPI (void){    SPIC1_SPIE = 1;   // SPI control register 1 setup   SPIC1_SPE = 1;    // SPI enable   SPIC1_SPTIE = 0;  // Transmit interrupt enable   SPIC1_MSTR = 0;   // Slave select   SPIC1_CPOL = 0;   // Clock polarity   SPIC1_CPHA = 1;   // Clock phase   SPIC1_SSOE = 0;   // Slave select output enable   SPIC1_LSBFE = 0;  // LSB first disabled      //SPIC2 = 0x00; // SPI control register 2 setup   SPIC2_MODFEN = 0;   SPIC2_BIDIROE = 0;   SPIC2_SPISWAI = 0;    SPIC2_SPC0 = 0; }  interrupt 15  // SPI receive interrupt   void receiveSPI (void){   int i;     for (i = 0; i<=dataSize; i++)   while(!SPIS_SPRF) SPIdataIn[i] = SPID;  // Wait for receive buffer flag, read data        SPIdataReceived = 1;     }

 

 

Outcomes