Wrong Baud

I have an NG hooked up to an LCD panel (the LCD-00462 Serial one from SparkFun), and about 1 in 3 times when it boots, it starts outputting at 19200 instead of the 9600 like I tell it.

The LCD panel shows garbage (like you'd see when you use the wrong baud) as does the Arduino IDE Serial Monitor (ver 0012) when it's set to 9600 baud. However when I change the Serial Monitor's rate to 19200, it's reads as designed.

I have an explicit "Serial.begin(9600)" statement in my code... this looks like a bug to me....

Has anyone else run into this problem?

-Earl

Weird. Can you post a small, complete example with the same problem?

If you change the Serial.begin() to 19200 do you have similar problems? (If the LCD expects 9600, this won't help you get it working, but it might help us figure out what's going on.)

That is weird. I read in the Sparkfun data sheet that the device can change it's baud rate on the fly by commands sent on the serial link.

Could it be something in the bootloader is sending characters out at reset time that cause the display to change it's baud rate to 19200, and then can't receive at 9600 to match what you are setting your sketch to?

So does the bootloader send out a (control 'o' ) character sequence after a reset? As that is the serial command that would cause the Sparkfun device to change from it's default 9600 to 19200 baud.

EDIT: I guess a better question is: is the serial display device wired to and seeing the same data steam on pin 0 when the IDE is uploading the sketch to the Arduino board? If so the data stream from an upload could be causing the display to change it's baud rate. I guess a test could be after uploading a sketch, it you could just remove the power lead to the display module that should cause it to reset and go back to it's default 9600 baud rate and then if your sketch works ok you will know what's causing this.

If it's not that then another it's a bizarre symptom :wink:

I've never been a fan of serial devices that allow themselves to change their own baud rate on the fly as any line garble or software mixup can cause this kind of symptom.

Lefty

This is not a problem with the LCD panel, it's the Arduino. Perhaps I wasn't clear enough. The LCD panel is NOT changing the baud. It continues to be set, and receive the data at 9600 baud.

It is the Arduino changing the baud at which it is transmitting. The Arduino IDE is watching the same output of pin 1 that the LCD is watching, and when I invoke the Serial Monitor at 9600 in the IDE, it receives the same garbage that the LCD is seeing. When I set the Serial Monitor to 19200, it receives the data correctly, and I continue to see garbage on the LCD.

Well then do have a very strange problem. I'm sure someone smarter then me will figure it out for you.

Lefty

If I had to hazard a guess of the first place to look, I'll betcha there's a bug in the NG bootloader, and it's sticking at 19200 baud after firing up.

Anybody feel like taking a look?

It ought not matter, since the bootloader will start the sketch at the normal location and execute the Serial.begin(9600) anyway.

Is there any way that statement could be skipped during your setup() ? If it is, the bootloader WILL have left the uart at 19200...

Can you post an example sketch that exhibits the bug? Have you tried uploading and running the sketch without the LCD attached to see if it works then?

Well, it's bigger than the forum allows you to post, so here's a link to it:

http://bangengineering.com/blog/?p=20

I've tried it with and without the LCD, same thing happens. Doesn't start a lot of the time, wrong baud about 25% of the time.

Currently trying it with a Duemilanove to see how the behavior differs...

If you change the Serial.begin() to 19200 do you have similar problems? What about 57600? The bootloader operates at 19200; maybe the Serial.begin() statement is changing the baud rate for some weird reason.

I came across the same problem with an arduino mini that I recently purchased. In my case, the baud rate is being set to exactly 1/2 the speed I tell it to.

For instance, if I specify Serial.Begin(9600), it will operate at 4800 (which I am determining by the arduino serial monitor - at that speed it reads correctly). If I set it to Serial.Begin(4800), it operates at 2400. If I specify Serial.Begin(19200), it operates properly at 9600.

I am guessing that some of these boards got shipped with a boot loader which somewhere is somehow dividing the baud by two. Could you test on yours if it is dividing perfectly by 2 as well?

-Nelson

The "half as fast" case can be explained if the fuses on the AVR get programmed to use the internal oscillator (8Mhz) instead of the crystal (16MHz.) But it's hard to explain "twice as fast", since the AVR shouldn't even run at 32MHz...

Um. When you say it runs "sometimes" at 19200, does that mean that sometimes a uploaded sketch runs consistently at 19200, while other times after upload it runs consistently at 9600? Or that the same uploaded sketch runs sometimes at 9600 and sometimes at 19200? (that is, is upload part of your normal "boot" or not. Your initial message implies not, but it also implies that you're still connected with the IDE's serial monitor, so it's not clear.)
Double speed COULD be cause by having the "board" menu accidentally set to board that normally runs at 8Mhz...

isn't there a bit to double the speed?
U2X0 in the UCSR0A Control and status register?

It appears to have been fixed in the Duemilanove, so I'd be very surprised if it was anything but a bug in the NG bootloader.

I seem to be having the exact same problem. Every once in a while my LCD (not the Spark-Fun one, but the same flavour) does this, and I spent ages assuming I had something wired incorrectly.

After mucking about, I inserted some debugging code (Serial.println's) and was greated with a whole lot of wrong-baud-rate jibber-jabber in the monitor.

I am explicitly setting Serial.begin(9600) and the monitor displays properly when I set it to 19200. I also modified my code to print (mills()/1000) to the LCD and it looks like the Arduino itself is running at double speed.

This is an Duemilanove and I have had similar projects working on it for several months.

Does anyone know how to fix this?! HELP!

Figures... 30 seconds after I posted this, I solved my own problem... I'm replying here in case anyone in the future has the same issue.

I had the IDE set to the wrong board type. Amazingly, it works fine now!