SPI - 08GB60

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

SPI - 08GB60

1,463 Views
Opal
Contributor I
Hello,
 
I have done one simple program in SPI .
From master sending one char contniously ,If reciver flag is set then after clearing the flag send the recived value to SCI. In slave , only clearing  the SPI reciver flag. Since In SPI when master start transmitting it will also start receving what ever data in the slave shift register at that time. So  from the second data of transfer from master. Master is expected to receive whatever data that send to slave previously.
 
Master Code:
while(1)
{
SPDR = name;
  while(!SPSCR_SPRF);  
    rec_data = SPDR;
   sendSCIchar(rec_data);
}
Slave code:
while(1)
 {
  
  while(!SPSCR_SPRF);  
       rec_data = SPDR;
}
 
When name =  'A'  Not getting A all the times.
When name =  'B'  Getting B contniouly.
When sending  two data in the while loop that is when sending A and B from master.
Getting AB contniously.
when name = 'C' Getting different characters in the middle.
when name = 'D' Getting D contniously.
 
when SPDR = 0xAA getting contniously.
when SPDR = 0xAB getting different character in the middle.
 
My assumption is when the characters equivalent binary ends with (LSB) 1 I am getting this problem.
I didnt understand why it is behaving differently Whether  problem with my Code. Or problem with my circuits.Or whether my understaning of SPI is not correct.
 
Kindly Help to solve this problem.


Message Edited by NLFSJ on 2008-01-14 04:07 PM
Labels (1)
0 Kudos
2 Replies

300 Views
Ake
Contributor II
Ohoh, It forgot my pictures.
They are included in the Sources
 
 
Regards,
Ake
 
Message Edited by t.dowe on 2009-10-27 12:52 PM
0 Kudos

300 Views
Ake
Contributor II
Hi,
I took two DEMO9S08GB60 boards and connected the MOSI/MISO/SS/SPSCLK and gnd wires together and started to play with your code.
I got the idea that you had mixed some of the signal names together, as I had to rewrite part of it.
However, I soon could send data from one MCU to another, and it worked just fine.
Well not all the time. Once the reception went wrong, it stayed wrong.
So I tried to use the /SS signal to tell the slave when a new byte of data was on its way.
But it turned out to be difficult in getting the /SS line to wiggle.
It seems that it wont go high until the line has been idle for at least one character transmission time.
So I changed that by pulling the I/O lines "by hand".
It seems to be working now.
The data transmitted was a string = "ABCD".
 
In your code you transmitted the received data from the SPI to the SCI.
As the SPI is generally far more faster than the SCI, that could also be one of the reasons why you got your problems.
 
I am including two photos. The top trace is the MOSI signal. The second is the /SS signal and the third the SPSCLK signal. The first photo shows what happens with the selector AUTOSLAVE set to TRUE.
In this case the SPI is taking care of the transmission. I had to add a delay between the characters in order to ever see the /SS signal go high.
On the second picture, I toggle the /SS signal by hand.
The pulses on the /SS are much shorter now.
 
To check what was received, you can stop the receiver and check the "error" counter.
It turned out to be 0 the last times I tried it.
 
The code was written in CodeWarrrior 6.1.
 
Hope this helps!
 
Regards,
Ake
 
Message Edited by t.dowe on 2009-10-27 12:54 PM
0 Kudos