PDA

View Full Version : Clearing Out RS232 registers



Bill Legge
- 23rd June 2009, 09:03
Is there a neat/short way of clearing out the registers associated with using RS232 (Serout, Serout2, HSEROUT) so that no 'junk' appears at the other end?

So far, Ive tried CRs, LFs and so on but still get a messy first line or so

Regards Bill Legge

Melanie
- 23rd June 2009, 12:52
When you first power-up, your hardware, registers, buffers can have all kinds of crap lurking. There's no real way of flushing this out, so the best thing I do is send a dummy line containg a dozen Nulls ($00) or so and terminate that with a CR LF. From then onwards, we're open for business.

Now, it all depends what is connected to what... if at the receiving end you've got an ANSI Terminal, then the next thing you'll send is a Clear-Screen, if it's an Invoicing printer, then you'd send a Page-Feed, POS Terminal you'd eject a couple of inches of paper along with a paper-cut command, etc etc...

If one PIC is connected to another, then I tend to send things in packets, and I always prefix the packet with some NULLs and a CR LF. The packet always has to have a valid header and a Checksum, otherwise it's dumped.

BrianT
- 8th July 2009, 02:03
I get over this problem by always starting with some preamble characters and either the WAIT (n) or QUALIFIER "A" characters. SERIN, SERIN2, HSERIN and DEBUGIN all have the ability to look for a defined character (or a string in the WAIT case) and toss out all the crud before that character or string.

HTH
BrianT