Brandon Castillo

SPI Issues

Discussion created by Brandon Castillo on Feb 15, 2007
Latest reply on Feb 20, 2007 by Brandon Castillo
Hello, I am using two 9S12E64 MCUs one as Slave and one as Master.  They are able to communicate with each other and as far as I know I am not having problems with the master, but I am having trouble getting the slave to send the desired data to the master.  Here is my master code.
 
Bit1_PutVal(0);
 delay(100);
 
 while(!SPISR_SPTEF);          // instruction
 (void)SM1_SendChar(0x05);
 while(!SPISR_SPIF);   
 delay(20000);
 
 while(!SPISR_SPTEF);           //dummy data to recieve 0xaa from slave
  (void)SM1_SendChar(0x00);
 while(!SPISR_SPIF);   
 delay(20000);
 
Bit1_PutVal(1); 
 
On the slave side, the slave reads 0x05 as an instruction to send 0xaa to the master.  My question is when do I put 0xaa into the SPIDR to where it will be sent when the master sends 0x00?  This is my slave code:
 
while(!(SPISR & 0x80));
       tester = SPISR;
        char0 = SPIDR;
if(char0 == 5){
       (void)SS1_SendChar(0xaa);
}
while(!(SPISR & 0x80));
What is wrong with my code?  How do I get 0xaa into the SPIDR before the second clock cycle?
 
Thanks for the help!

Outcomes