View previous topic :: View next topic |
Author |
Message |
rret
Joined: 01 Dec 2009 Posts: 9 Location: sherman CT
|
how to tell if done receiving chars |
Posted: Sat Feb 06, 2010 11:32 am |
|
|
I am writing a program that sends a message out the serial port at 115200 baud.
That message I send out causes "the other side" to respond back.
I am using ISR int_rda to receive chars and they come back in a "burst".
I stuff the received chars in a large buffer in the ISR.
Now for my question-
Does anyone have a way of figuring out when that burst is complete (i.e. no more chars are arriving)? |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sat Feb 06, 2010 1:45 pm |
|
|
Unique delimiters (e.g. CR or CR/LF) are the most simple method and actually used by almost any text based protocol. If applied to a binary protocol, esacpe sequences are required to keep it unique.
Binary protocols often contain a block length information, so an explicit delimiter wouldn't be neccessarily required. It's still useful in case of lost frame synchronization, however.
A timeout in combination with a required send delay is another means to synchronize blocks. It's used e.g. with MODBUS RTU. |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Sat Feb 06, 2010 1:48 pm |
|
|
or you could easily setup a watchdog timer to flag you that the rcv line has been idle after 'no more characters'... |
|
![](templates/subSilver/images/spacer.gif) |
bkamen
Joined: 07 Jan 2004 Posts: 1611 Location: Central Illinois, USA
|
|
Posted: Sat Feb 06, 2010 3:38 pm |
|
|
FvM wrote: | Unique delimiters (e.g. CR or CR/LF) are the most simple method and actually used by almost any text based
protocol. If applied to a binary protocol, esacpe sequences are required to keep it unique.
Binary protocols often contain a block length information, so an explicite delimiter wouldn't be neccessarily
required. It's still useful in case of lost frame synchronization, however.
A timeout in combination with a required send delay is another means to synchronize blocks. It's used e.g.
with MODBUS RTU. |
Right. I've also seen header sync bytes/words. Something that's particularly unique enough to indicate a start of packet.
I can also second the concept of a timeout strongly.
I've been writing a couple PIC apps for a client that sends a lot of 16bit data over RS232 (which is typically 8bits per word.) So that means I have to make sure to think in words even though the data is coming in byte sized chunks. (hahaha, BYTE SIZED -- har har).
What if I don't get an even number of bytes? It should definitely cause the state machine in #INT_RDA to somehow timeout and reset.
I do that with timers, CMD chars, and buffer limits.
Be VERY paranoid. :D
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
![](templates/subSilver/images/spacer.gif) |
arloedx
Joined: 21 Aug 2009 Posts: 15 Location: Texas
|
|
Posted: Wed Apr 07, 2010 3:45 pm |
|
|
bkamen: I'm also looking into sending & receiving 16-bit data via RS-232. Do you have a sample I may use as a foundation to my code. It would save me a lot of time. I would appreciate any help. Thank you. |
|
![](templates/subSilver/images/spacer.gif) |
bkamen
Joined: 07 Jan 2004 Posts: 1611 Location: Central Illinois, USA
|
|
Posted: Wed Apr 07, 2010 6:13 pm |
|
|
arloedx wrote: | bkamen: I'm also looking into sending & receiving 16-bit data via RS-232. Do you have a sample I may use as a foundation to my code. It would save me a lot of time. I would appreciate any help. Thank you. |
First tell me this:
are you originating data or are you repeating it? I was building a repeater. I had synchronous 16bit data coming in to be repeated out to a PC on RS232 (which is 8 bits) --- and vice versa (PC @ 8bits back to device on 16bit sync line)
Tell us about your app first.... we'll go from there.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
![](templates/subSilver/images/spacer.gif) |
arloedx
Joined: 21 Aug 2009 Posts: 15 Location: Texas
|
|
Posted: Thu Apr 08, 2010 8:50 am |
|
|
Hi Ben,
Thanks for the quick reply. In my app, data is being processed by an external A/D Converter then saved on the PIC. That part is easy enough. I then need to send the data from one PIC to another PIC. The data is 16-bits long. Here is where it gets a little complicated. I have successfully sent 8 bit packets and figured it would be simple enough to break up the 16-bit data into two 8-bit chunks, transmit them, then put them back together in the other PIC but after reading your post I became VERY paranoid...hehe. I realize too much could go wrong if I did only that. SO i was looking for examples or suggestions. Thanks again,
-Alex |
|
![](templates/subSilver/images/spacer.gif) |
bkamen
Joined: 07 Jan 2004 Posts: 1611 Location: Central Illinois, USA
|
|
Posted: Thu Apr 08, 2010 8:53 am |
|
|
nope. not much else you can do.
The UARTS operate in an 8bit mode. So you have to start making packets.
It's not too bad.. just make sure to cross all your T's and dot the I's.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
![](templates/subSilver/images/spacer.gif) |
arloedx
Joined: 21 Aug 2009 Posts: 15 Location: Texas
|
|
Posted: Thu Apr 08, 2010 9:18 am |
|
|
Ok. Thanks.
-Alex |
|
![](templates/subSilver/images/spacer.gif) |
|