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

Number of characters in the RS232 buffer.

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



Joined: 21 Sep 2005
Posts: 4

View user's profile Send private message

Number of characters in the RS232 buffer.
PostPosted: Wed May 10, 2006 2:57 pm     Reply with quote

Hi developers,

How is possible to know how many characters there are in the RS232 buffer? When I entry in the USART Interrupt routine, I need to know how many characters are still there from to unload.

Do you have some idea?

Thank you, have a good job.
rberek



Joined: 10 Jan 2005
Posts: 207
Location: Ottawa, Canada

View user's profile Send private message

PostPosted: Wed May 10, 2006 3:39 pm     Reply with quote

Well, there are a maximum of two, as far as I remember. But why would expect multiple characters in the buffer?

If you have not disabled the RDA interrupt and are not trying to too much inside the ISR, you should only have one character at a time in there anyway. If you think you might see more than one, than that means you may not be servicing the interrupt frequently enough. The buffer is tiny and easy to overflow.
mtar



Joined: 21 Sep 2005
Posts: 4

View user's profile Send private message

Number of characters in the RS232 buffer.
PostPosted: Wed May 10, 2006 4:44 pm     Reply with quote

First of all thank you for your answer!

I understand that my question is strange. I need to receive a fixed number of characters from the RS232 port in established time.
With other compilers (Rabbit for example), I can decide to read the buffer (adjustable) when I have the correct number of characters in the FIFO.

Anyway I will now do otherwise, thanks still.

Bye
treitmey



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

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

PostPosted: Thu May 11, 2006 8:23 am     Reply with quote

I think what you what to do then is let the hardware USART and an ISR handle putting the data into a circular buffer. Then check the buffers in and out pointers to find the number of char recieved.
mtar



Joined: 21 Sep 2005
Posts: 4

View user's profile Send private message

Number of characters in the RS232 buffer.
PostPosted: Fri May 12, 2006 1:17 am     Reply with quote

In fact I will do so, thanks.

The possibility to know how much byte there are in the buffer, before unloading them, it is very useful when you have to verify that one determined quantity of byte has arrived in established time.
The protocol that I am using is binary. It doesn't have the CR or LF characters at the end of every command, therefore the number of byte must have determined.

I have thought to activate a timer when the first byte arrives, when the timer is halted to verify that the quantity of byte is correct, otherwise clear the buffer and to send an error.

Do you know if there is already some example of this code (in order of resolve this problem) in this forum? Thank you.

Bye
treitmey



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

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

PostPosted: Fri May 12, 2006 7:46 am     Reply with quote

Yes, modbus from Neutone..
http://www.ccsinfo.com/forum/viewtopic.php?t=19306
What I do is this...
My protocol states that there must be x milisecond of idle time between packets.
I start a timer when I start recieving a packet.
I reset the timer every time my ISR takes bytes from USART and puts in circular buffer.
At the end of a packet the timer will time to the x miliseconds.
I then take all data from circular buffer and copy it to a struct with my
defined protocol.
At the end of my packet is a checksum. If it doesn't match, data is invalid.

This way if I start Rx in the middle of a packet. I copy the data over to the packet stucture and my checksum won't match, I dump it, and the next packet I should Rx the whole thing and every thing starts running fine.
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