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 CCS Technical Support

SPI: How to send/receive many bytes from Pic to Pic?

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



Joined: 26 Apr 2006
Posts: 38
Location: Portugal

View user's profile Send private message

SPI: How to send/receive many bytes from Pic to Pic?
PostPosted: Sat Apr 29, 2006 11:16 am     Reply with quote

Hi forum!


I am using 2 PICs 16f877 and i need to send/receive several bytes.

question is: how to "synchronize" transmission?


i need to implement such a protocol, with request -> acknowledge -> useful info -> end of transmission.

which is the best way to do this??
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat Apr 29, 2006 4:14 pm     Reply with quote

You can have a look at the following thread for some design ideas: http://www.ccsinfo.com/forum/viewtopic.php?t=25980
cjusto



Joined: 26 Apr 2006
Posts: 38
Location: Portugal

View user's profile Send private message

PostPosted: Sun Apr 30, 2006 6:16 am     Reply with quote

Hi forum!


Thank you ckielstra.

i checked all this info. and that kind of protocol is what i have in mind.

my problem is how to know the instant when the byte in the spi port is available.
i can already send and receive bytes. but it's hard to receive what i am expecting. because there are other functions to be done meanwhile.


i am trying to implement such a protocol where the master pics starts the communication. slave answers informing if there is info to be send or not.



how to do this?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon May 01, 2006 3:35 am     Reply with quote

Quote:
my problem is how to know the instant when the byte in the spi port is available.
The spi hardware can generate an interrupt signal when new data is ready to be read.

Quote:
i can already send and receive bytes. but it's hard to receive what i am expecting. because there are other functions to be done meanwhile.
This is a classical situation for which interrupts where designed for. You will have to write an interrupt routine that will become active on SPI data reception and then stores the received data in a large save buffer.
Your other functions can do their things but on data reception the interrupt will become active, read and store your data after which your normal program flow is continued again. At a later time, that you decide on, you can check for the large receive buffer to contain data and process it.

Depending on the data you are transmitting you can set up the receive buffer as a linear or ring buffer. The following thread is a discussion on when to use either buffer type: http://www.ccsinfo.com/forum/viewtopic.php?t=6446

An example of an interrupt based cyclic buffer is EX_SISR.C in the CCS example directory.
cjusto



Joined: 26 Apr 2006
Posts: 38
Location: Portugal

View user's profile Send private message

PostPosted: Mon May 01, 2006 2:33 pm     Reply with quote

thanks ckielstra.

i will try that. implementing a save buffer should work.

thank you.
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