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 CCS Technical Support

avoid garbage characters in serial terminal

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



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

avoid garbage characters in serial terminal
PostPosted: Mon Jun 27, 2011 3:22 pm     Reply with quote

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
asmboy



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

View user's profile Send private message AIM Address

code dependant possibility
PostPosted: Mon Jun 27, 2011 5:57 pm     Reply with quote

Perhaps you would care to post your program so the issue can be analyzed
with a few more "true facts" to go on.
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Tue Jun 28, 2011 2:09 am     Reply with quote

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
cerr



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

PostPosted: Tue Jun 28, 2011 9:49 am     Reply with quote

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...
temtronic



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

View user's profile Send private message

PostPosted: Tue Jun 28, 2011 9:57 am     Reply with quote

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
cerr



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

PostPosted: Tue Jun 28, 2011 10:33 am     Reply with quote

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?
temtronic



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

View user's profile Send private message

PostPosted: Tue Jun 28, 2011 11:07 am     Reply with quote

no..one to two seconds, not milliseconds.
cerr



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

PostPosted: Tue Jun 28, 2011 11:48 am     Reply with quote

temtronic wrote:
no..one to two seconds, not milliseconds.

Hoops yes, that's what I meant of course...
Ok, I'll do that. Thanks!
Sergeant82d



Joined: 01 Nov 2009
Posts: 55
Location: Central Oklahoma

View user's profile Send private message

Printing Garbage Characters
PostPosted: Sun Jul 10, 2011 12:42 pm     Reply with quote

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...
cerr



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

Re: Printing Garbage Characters
PostPosted: Mon Jul 11, 2011 9:44 am     Reply with quote

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...
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