CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Using SPI Functions in Slave Mode

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
DaveThib



Joined: 17 Oct 2004
Posts: 15
Location: New Hampshire USA

View user's profile Send private message

Using SPI Functions in Slave Mode
PostPosted: Fri May 20, 2005 1:05 pm     Reply with quote

In a recent project I used two pics. They communicated using SPI with one in slave mode. I am exchanging two byte commands between the PICs so using SPI is very handy. Every time they communicate they either send real data or null data to each other at the same time. My programs in both chips have a lot going on and cannot wait for the data to clock in or out. I am using state machines and I go away while the data is clocking and come back when it is ready. On the master side it is quite easy by using SPI_Data_Is_In() and then just using a SPI_READ() to read the data without a clock. When I start the clock I use SPI_WRITE(data) to clock and send data.

Now moving over to the slave side of things. When the master processor signals that the slave needs to load the buffer I then need to load the buffer. I can use the SPI_WRITE(data) to do this but then I noticed that it waits around for all eight bits to clock in before continuing. I DO NOT want to hang around and wait for the data to clock in. I do not see anywhere in the refenerence manual where I can load the SSPBUF and not wait around for the data. Is there something I am missing?

I got around this problem by mapping the SSPBUF memory location to a variable and writing directly to it. I then can go on doing other things and I keep checking back using SPI_Data_Is_In() and it is working just great. It just seems to me there should be a way to do this using standard functions.

Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri May 20, 2005 1:27 pm     Reply with quote

Quote:
It just seems to me there should be a way to do this using standard functions.

Not necessarily. The standard functions only have whatever features
that the programmer at CCS decided to put into them. Whenever you
want more advanced features, you may have to write your own
functions.

See this thread. CCS didn't (or doesn't) support the 2nd MSSP
channel on a particular PIC. So I show how to add SPI support
for the 2nd channel. You're interested in the SPI write function,
so you could look at the C code for it, and modify it to remove
the BF flag check.
http://www.ccsinfo.com/forum/viewtopic.php?t=22705
DaveThib



Joined: 17 Oct 2004
Posts: 15
Location: New Hampshire USA

View user's profile Send private message

Thanks
PostPosted: Fri May 20, 2005 1:41 pm     Reply with quote

OK, Well I guess I was not that far off since that is basically what I did. I do have a project starting soon that I will need to use two MSSP modules so you just saved me a couple of hours of "how do I?" frustrations!

I also noticed in this last project that there is no standard argument in Setup_SPI to disable the Slave Select. It was not a big deal since I am getting used to how to get around unsupported features.

Thanks Again!
Ttelmah
Guest







PostPosted: Fri May 20, 2005 2:22 pm     Reply with quote

For doing the 'slave' in the past, I had the similar problem, and used:
Code:

#byte   SSPBUF = 0xFC9
#byte   SSPCON = 0xFC6
#byte   I2CBUF = 0xFC8
#byte   SSPSTAT = 0xFC7
/* Now the SSP handler code. Using my own, since the supplied routines test the wrong way round for my needs */
#DEFINE       READ_SSP()   (SSPBUF)
#DEFINE   WAIT_FOR_SSP()   while((SSPSTAT & 1)==0)
#DEFINE   WRITE_SSP(x)   SSPBUF=(x)
#DEFINE   CLEAR_WCOL()   SSPCON=SSPCON & 0x3F

These allow 'lower level' access, just putting the byte into the or reading the byte from the buffer, with seperate tests if required.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group