SPI configuration

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

SPI configuration

1,717 Views
Dev
Contributor I
Hi! I'm trying to transmit a byte from SPI0 to SPI1, for which I tried using the below given code- --------------------------------------------------------- void main(void) { SPI0CR1=0x5F;//SPIO enabled and cofigured as master SPI0CR2=0x00; SPI0BR=0x77; SPI1CR1=0x48;//SPI1 enabled and configured as slave SPI1CR2=0x00; SPI1BR=0x77; EnableInterrupts; for(;:smileywink: { while(!SPI0SR_SPTEF ); SPI0DR=0x78; while(!SPI1SR_SPIF); i=SPI1DR; } } ----------------------------------------------- and also this is being run as Full Chip Simulation where i've used the following command file to virtually connect MOSI0 to MOSI1 and SCK0 to SCK1 ------------- openio pinconn connect "Pim.PORTSPin5","Pim.PORTPPin1" connect "Pim.PORTSPin6","Pim.PORTPPin2" ------------- My problem is, while the Txd byte is available at MOSI0, the same is not being transmitted to SPI1, or in other words, data is not getting written onto the SPI1... Can someone please help me figure out the problem.. Regards, Dev
Labels (1)
0 Kudos
Reply
2 Replies

537 Views
bigmac
Specialist III
Hello Dev, and welcome to the forum.
 
What happened to the formatting of your post?  Always a good idea to check immediately after posting, and if necessary, edit your post.
 
I can't be sure about the validity of your virtual connection - others may need to assist here.  But you may also need to consider the SS connection between master and slave (since the slave operation has set CPHA = 0).
 
I can see a number of problems with the code you have posted -
  1. You seem to have a mismatch between master and slave channels with respect to the control bits LSBFE and CPHA.  This is not permissible.
  2. I would assume that you intend to operate with automatic operation of the master SS line as an output (SSOE = 1).  This also requires that MODFEN = 1 (SPI0CR2 = 0x10).
  3. Even though you are not using the return data from the slave channel, you will still need to clear the flag to prevent an overrun condition.  This will require SPI0DR to be read.
  4. While not a problem per se, be aware that setting the baud rate for the slave channel fulfills no purpose.  The master will determine the clock rate at which the slave operates.
Part of the modified code is reflected below -.
 
while (!SPI0SR_SPTEF );
SPI0DR = 0x78;        /* Send byte to master */
while (!SPI0SR_SPIF); /* Wait for transmission complete */
i = SPI0DR;           /* Clear flag for master */
while (!SPI1SR_SPIF); /* Clear flag for slave */
i = SPI1DR;           /* Byte value received by slave */
 
Regards,
Mac
 
0 Kudos
Reply

537 Views
Dev
Contributor I
Hello bigmac,

as i was posting here for the first time,
I didn't notice the check and edit options.
Sorry or that, I'll ensure that I don't repeat
them again.

Yep, as u have pointed out,
SPI1CR1=0x4F. So silly of me!!

And wrt this program- it works fine
on the muc.. But the same prog didn't
work when set under "Full Chip Simulation".
So, I guess there is something wrong with
that virtual conection stuff that I've used.


Thanks a lot.
Regards,
Dev

Message Edited by Dev on 2008-01-29 05:55 PM
0 Kudos
Reply