[MC9S08JM60] Problems with MCU SPI slave

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

[MC9S08JM60] Problems with MCU SPI slave

982 Views
Koolmelee
Contributor I

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 SPI_MCU1Read()
{
     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;
}

Labels (1)
0 Kudos
3 Replies

339 Views
PeterHouse
Contributor I
Make sure you connected the Master MISO to Slave MOSI and the Master MOSI to Slave MISO. Good Luck, Peter
0 Kudos

339 Views
bigmac
Specialist III

Hello,

 

MISO pins must connect together at each end, as must the MOSI pins.  For the SPI module, MISO is an input for master operation, and an output for slave operation, and vice versa for MOSI.  The switching between input and output is done within the module hardware.

 

If you are attempting to single step through the function SPI_MCU1Read(), in all probabilily the debugger's actions will clear the flag before the test can occur within the code.  Use a suitable break point rather than single stepping.

 

Since you have used macros for the SPI initialisation, it is impossible to confirm whether the actual initialisation matches to your stated intent, without knowing the value of each macro.

 

 

Regards,

Mac

 

0 Kudos

339 Views
PeterHouse
Contributor I
Oops. My Mistake. My lame excuse is I used SPI before they were called MOSI and MISO and before they were switched by the hardware and you had to cross connect them. Who made me a trusted contributor anyway :smileyhappy: ??? :smileyhappy: Peter
0 Kudos