James Cotter

[MC9S08JM60] Problems with MCU SPI slave

Discussion created by James Cotter on Aug 4, 2010
Latest reply on Aug 5, 2010 by Peter House

So I have 2 MC9S08JM60 microcontrolers that I have connected through spi.


I have the master MCU sending data out properly (I have scoped this out-->clk, data and chip select and the signals look great on both the output pins of the master MCU and the input pins of the slave MCU.) However, the problem lies in the slave. I poll SPRF, but it never seems to get set.


Here is my initialization for the Slave MCU.


void MCU1COMM_init() {
  /*Pin Initialization*/
   /*SPI module initialization*/
      SOPT2_SPI2FE = 0;        //Disable the spi filter for > 6Mhz transmission
        //--SPI Control Register 1--
          //No interrupts,
          //SPI enabled,
          //Normal polarity/phase(active high clk),
          //slave mode
          //MSB first,
      SPI2C1 = SPI2C1_SPE_MASK; //Enable
          //--SPI Control Register 2--
          //Disable interrupts
          //16 bit transfers
          //Master mode fault disabled
          //Bidirectional disabled
          //Spi stop in wait mode
          //spi pin control disabled
      SPI2C2 = SPI2C2_SPIMODE_MASK;     // 16 bit xfer



Here is the function I call in a loop continuously in the main


     UINT8 temp1=0, temp2=0;
     UINT8 index;
     UINT8 result = 0;
     if(SPI2S_SPRF)   //data has been recieved
        temp1 = SPI2DH;
        temp2 = SPI2DL;
         if(temp1 == DATAINCOMING)
             result = 1;
             for(index = 0; index < temp2; index++)   //recieve 16 bytes
                 while(!SPI2S_SPRF);     //wait for read flag to be set
                 MCU1_Datain[index] =  SPI2DH;       //grab the data
                 MCU1_Datain[index + 1] = SPI2DL;
     return result;