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 support@ccsinfo.com

Detecting Serial TX end of string

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



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

Detecting Serial TX end of string
PostPosted: Fri Apr 17, 2015 9:01 am     Reply with quote

Hi All,

Anyone have any ideas on how to detect the end of a transmission by serial?

To detect the START i usually poll the index of my receiving buffer.
But how can you detect when the transmission ENDS of an undefined number of characters.

When setting up GSM stuff i normally operate with fixed delays AFTER the first character of the incoming string has been received. This works well most of the time but, it gets slow quickly since i need to allow time for the longest messages by fixed delay. Some messages are shorter thus things can move on but i need to wait the same amount of time as if it were a long message.

So any ideas on HOW to detect the end of an incoming transmission/string of undefined length?


G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Apr 17, 2015 10:27 am     Reply with quote

One idea...did this 24 years ago..don't ask WHY I know it's was 24 years ago....

You could poll the RX line and see if it's returned to 'idle'. Tst to see it's it's been idle for say 5 bit times, if so , then flag and consider it 'End Of Transmission'.

Jay
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Fri Apr 17, 2015 11:15 am     Reply with quote

Hi Mr. T, would that interfere with the UART operation?

i guess polling does not really alter the pins operation regardless of what peripheral is using it.

ill try that.

thanks!
G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Sat Apr 18, 2015 1:14 am     Reply with quote

This is all down to what you are sending, and the nature of the communications.

With direct wired comms, then you can design your packet to always send as an unbroken 'entity', and as Temtronic says, use a timeout. This is how Modbus normally works. This though can have problems if sending over radio links that in some cases are themselves 'packetised'. With this type of link, the modems communicate between themselves at a higher rate than the serial link, using their own packets and automatically re-sending when there is an error. This then results in a pause in the received packet, which gives problems using the timeout approach. The same happens over things like Bluetooth links. This is why Modbus specifically allows other methods to be used on such links. One answer then is if you are sending ASCII, to use the STX/ETX characters, or switch to things like 9bit, to mark the start and end of your packet. You need to look at the nature of your data, and the links involved, and design your format to have some suitable marker that will work over all the sections involved.

Simplest is often to send data 'plain text', and use STX/ETX.

For the timeout, you don't have to poll the pins. You can simply set a timer in the receive interrupt. reset it whenever a character is seen. Use a count value, that will reach the terminal count after some number of characters (3.5, 5, whatever you choose), and then when there is a pause in received characters this long, the timer will reach it's terminal count, and the timer interrupt will trigger, marking the end of packet.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Sat Apr 18, 2015 10:15 am     Reply with quote

while a timeout MAY be the answer - many devices may insert their own pauses in a defined data stream -so absolute timing of your timeout might still fail.

you never mention if YOU are in control of the content of the input serial stream and can tag a sequence with a "safe" character such as the Carriage return.

were that true -adding a simple character compare in your receive ISR
handles it nicely w/ resorting to timebased monitoring.
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Mon Apr 20, 2015 6:32 am     Reply with quote

I have a wired conection to a gsm modem.

This type of modems have diferent delays to start sending a reply (in my experience), but i have yet to encounter a delay during transmision. i have an easy way to manage that initial delay.

I like the timer/interrupt solution! Elegant and simple.

Looking for '\r' or other characters is cumbersome since when reading a SMS, the modem outputs mutiple 'safe' characters.
I do not control the output or format of the modem....

Thanks
G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
dyeatman



Joined: 06 Sep 2003
Posts: 1912
Location: Norman, OK

View user's profile Send private message

PostPosted: Mon Apr 20, 2015 4:04 pm     Reply with quote

What kind of modem is this that doesn't have terminators?
If this is data being received by the modem where is it coming from?
_________________
Google and Forum Search are some of your best tools!!!!
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Mon Apr 20, 2015 8:26 pm     Reply with quote

I'm assuming that by terminators you are referring to returns and newlines... in any given data stream from the modem to the pic, there are multiple returns ans newline characters.

The modem always also sends the classic OK string or ERROR.

but i cant poll the buffer for returns or new lines cause there are multiple said characters per sent data and i cant search for the OK until the stream is done since its the last thing it sends....

Thus this thread.

The data from the modem... come from.... other... phones. Like an SMS that says "lights on" or what ever command i might think of.
_________________
CCS PCM 5.078 & CCS PCH 5.093
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Tue Apr 21, 2015 2:39 am     Reply with quote

If you are receiving an SMS PDU message, then the octet before the start of the text, is the data length. So then just count the characters.
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