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

XON/XOFF flow control

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







XON/XOFF flow control
PostPosted: Sun Jul 27, 2003 1:07 pm     Reply with quote

Does anyone perhaps have advise or example code to do XON/XOFF serial comms flow control between a PIC16F877 and a modem?

Thank you

Levett
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516403
R.J.Hamlett
Guest







Re: XON/XOFF flow control
PostPosted: Wed Jul 30, 2003 3:14 am     Reply with quote

:=Does anyone perhaps have advise or example code to do XON/XOFF serial comms flow control between a PIC16F877 and a modem?
:=
:=Thank you
:=
:=Levett
Use a ring buffer on receive (do a search here for details of this). Have a counter reflecting how many characters are in this. When adding characters to the buffer check the counter. If it rises beyond an arbitrary size (depends on the size of the buffer, and the likely size of the FIFO at the other end - I have used a count of '44', with a 64 character buffer), then add a 'XOFF' character to the output. I have the 'output' routine modified, so it too has a buffer, but also has a 'handshake' byte stored seperately. To send XOFF, this is put into the 'handshake' byte. The interrupt driven transmit code, tests this byte for being non-zero, _before_ sending the next character from the output buffer. In the event there is a handshake character waiting, this is sent, the byte is cleared, and the routine returns. If there is no handshake character, the next character from the output buffer is sent instead. This way the handshake character 'pre-empts' the data waiting in the output buffer.
Now the receive code also checks for the buffer dropping to a 'low' value (I used 16 characters), and then sends 'XON' the same way.
The receive code also checks if the character received, is either XON, or XOFF. In the latter case, I disable the TBE interrupt (which stops data from being sent), while the XON character turns this back on.
Now I was talking to a PC, which had large(ish) FIFO buffers, so when I sent 'XOFF', I'd still typically receive perhaps another 14 characters, before the communications stopped, hence my use of a large buffer, and sending the stop at 44 characters. In this case very large strings were being sent in both directions, with quite a lot of processing involved. Generally, provided your own comm routine, is interrupt driven, and fast, there may be no need for you to ever send 'XOFF', so you only have to handle the handshake in the transmit direction, which is easy to do by just disabling/enabling the transmit interrupt. :-)

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516492
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