![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
g159 Guest
|
Reading data from RS-232 into PIC memory |
Posted: Thu Oct 25, 2007 2:23 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Ken Johnson
Joined: 23 Mar 2006 Posts: 197 Location: Lewisburg, WV
|
|
Posted: Thu Oct 25, 2007 6:41 am |
|
|
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
Ken |
|
![](templates/subSilver/images/spacer.gif) |
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Thu Oct 25, 2007 8:13 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|