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

how to tell if done receiving chars

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



Joined: 01 Dec 2009
Posts: 9
Location: sherman CT

View user's profile Send private message

how to tell if done receiving chars
PostPosted: Sat Feb 06, 2010 11:32 am     Reply with quote

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)?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Feb 06, 2010 1:12 pm     Reply with quote

Look at the NMEA-0183 protocol (for example). It uses a CR-LF pair
to indicate the end of message. This is suitable for a protocol that sends
ASCII messages:
http://en.wikipedia.org/wiki/NMEA_0183#Application_layer_protocol_rules
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sat Feb 06, 2010 1:45 pm     Reply with quote

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.
Guest








PostPosted: Sat Feb 06, 2010 1:48 pm     Reply with quote

or you could easily setup a watchdog timer to flag you that the rcv line has been idle after 'no more characters'...
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sat Feb 06, 2010 3:38 pm     Reply with quote

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
arloedx



Joined: 21 Aug 2009
Posts: 15
Location: Texas

View user's profile Send private message

PostPosted: Wed Apr 07, 2010 3:45 pm     Reply with quote

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.
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Wed Apr 07, 2010 6:13 pm     Reply with quote

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
arloedx



Joined: 21 Aug 2009
Posts: 15
Location: Texas

View user's profile Send private message

PostPosted: Thu Apr 08, 2010 8:50 am     Reply with quote

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
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Thu Apr 08, 2010 8:53 am     Reply with quote

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
arloedx



Joined: 21 Aug 2009
Posts: 15
Location: Texas

View user's profile Send private message

PostPosted: Thu Apr 08, 2010 9:18 am     Reply with quote

Ok. Thanks. Smile

-Alex
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