View previous topic :: View next topic |
Author |
Message |
cerr
Joined: 10 Feb 2011 Posts: 241 Location: Vancouver, BC
|
avoid garbage characters in serial terminal |
Posted: Mon Jun 27, 2011 3:22 pm |
|
|
Hi There,
Does anyone know of a method to have a defined start of valid data over a rs232 serial connection? I'm getting garbage characters right after initialization and after an undefined amount of garbage, I start getting valid characters/data. Is there a way that I can clean up all the garbage and start with clean characters from a defined point on?
Thank you!
PIC18F86K22, 19200bps @ 20MHz |
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
code dependant possibility |
Posted: Mon Jun 27, 2011 5:57 pm |
|
|
Perhaps you would care to post your program so the issue can be analyzed
with a few more "true facts" to go on. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19375
|
|
Posted: Tue Jun 28, 2011 2:09 am |
|
|
General method though, is at the start of your code, wait for the serial RX line to go high, and only then start the UART.
So:
Code: |
#use RS232(UART1, BAUD=0, ERRORS)
//Then at the start of main
while (input(PIN_C7)==0) {
//Have a timeout here if the line has not gone high after a second or so
//display an error or whatever.
}
setup_uart(9600); //actually start the UART
|
It is common for it to take quite a few mSec for serial lines to stabilise.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
cerr
Joined: 10 Feb 2011 Posts: 241 Location: Vancouver, BC
|
|
Posted: Tue Jun 28, 2011 9:49 am |
|
|
Ttelmah wrote: | General method though, is at the start of your code, wait for the serial RX line to go high, and only then start the UART.
So:
Code: |
#use RS232(UART1, BAUD=0, ERRORS)
//Then at the start of main
while (input(PIN_C7)==0) {
//Have a timeout here if the line has not gone high after a second or so
//display an error or whatever.
}
setup_uart(9600); //actually start the UART
|
It is common for it to take quite a few mSec for serial lines to stabilise.
Best Wishes |
Thanks, I implemented this, makes it slightly better but I still see a whole bunch of garbage when I power up my system... |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9176 Location: Greensville,Ontario
|
|
Posted: Tue Jun 28, 2011 9:57 am |
|
|
Maybe add a small routine to read and purge the serial port for say 1-2 seconds, then use Ttelmah's routine ?
I always have a 1-2 second delay before I allow 'main' to run .This is done between the LCD displaying..'startup' and then 'pgm name'.
it might help....worth a try ?
Jay |
|
![](templates/subSilver/images/spacer.gif) |
cerr
Joined: 10 Feb 2011 Posts: 241 Location: Vancouver, BC
|
|
Posted: Tue Jun 28, 2011 10:33 am |
|
|
temtronic wrote: | Maybe add a small routine to read and purge the serial port for say 1-2 seconds, then use Ttelmah's routine ?
|
What does this mean, you just wait 1 or 2 ms before you proceed with Ttelmah's routine? |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9176 Location: Greensville,Ontario
|
|
Posted: Tue Jun 28, 2011 11:07 am |
|
|
no..one to two seconds, not milliseconds. |
|
![](templates/subSilver/images/spacer.gif) |
cerr
Joined: 10 Feb 2011 Posts: 241 Location: Vancouver, BC
|
|
Posted: Tue Jun 28, 2011 11:48 am |
|
|
temtronic wrote: | no..one to two seconds, not milliseconds. |
Hoops yes, that's what I meant of course...
Ok, I'll do that. Thanks! |
|
![](templates/subSilver/images/spacer.gif) |
Sergeant82d
Joined: 01 Nov 2009 Posts: 55 Location: Central Oklahoma
|
Printing Garbage Characters |
Posted: Sun Jul 10, 2011 12:42 pm |
|
|
FWIW, I have this problem all the time also; I just use a
delay_ms(5)
just prior to, and immediately after, my first call to printf(). It has always cured the problem for me... no need for entire seconds... |
|
![](templates/subSilver/images/spacer.gif) |
cerr
Joined: 10 Feb 2011 Posts: 241 Location: Vancouver, BC
|
Re: Printing Garbage Characters |
Posted: Mon Jul 11, 2011 9:44 am |
|
|
Sergeant82d wrote: | FWIW, I have this problem all the time also; I just use a
delay_ms(5)
just prior to, and immediately after, my first call to printf(). It has always cured the problem for me... no need for entire seconds... |
Uhm, that doesn't really do the trick for me. What baudrate are you running at? My system is at 19.2kbps... |
|
![](templates/subSilver/images/spacer.gif) |
|