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

Reading data from RS-232 into PIC memory

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







Reading data from RS-232 into PIC memory
PostPosted: Thu Oct 25, 2007 2:23 am     Reply with quote

Hi guys,

I am trying to interface my PIC to an external device which communicates through RS-232. Basically the PIC sends out a command, and the external device responds with blocks of bitstreams, say, maybe 3 bitstreams for each command. Each bitstream is separated from each other by about 10 ms (the stream is just idle +12 V in between). I want to store each bitstream into separate buffers, or variables. I know that something like gets() and getchar() can do the trick, but how do you handle the fact that you want the first bitstream encountered to be stored into one buffer, and the next one 10ms later into a different one? Is there a convenient way to do this?

Thanks guys, you guys are really wonderful and helpful.
Ken Johnson



Joined: 23 Mar 2006
Posts: 197
Location: Lewisburg, WV

View user's profile Send private message

PostPosted: Thu Oct 25, 2007 6:41 am     Reply with quote

If you're designing your own protocol, use special characters to identify the start/end of a message, e.g. <STX>....<ETX> (any characters will do, provided they don't appear 'inside' the message proper).

If not, you can set a timer with each byte received. When it times out (interrupt), then you have one message (assuming each message is sent without gaps).

Hope this helps Smile

Ken
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Thu Oct 25, 2007 8:13 am     Reply with quote

sounds kind of like the idle bus thing I use in RS485 protocol.
I set a timmer, so its a little less than 10ms
then in the int_rda reset the timmer.
thus it can't count down much until the serial port is idle.
Then after 10ms idle , you could switch to a different buffer.
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