I tried to switch my Duemilanove for a Uno and I have been experiencing serial communication issues.
I am using OS X 10.6.
I bought my Arduino Uno from Sparkfun.
The Arduino is connected by USB directly to the computer.
I am using the Arduino IDE 0021.
When the baud is set to 57600 the Arduino Uno returns gibberish. For example, if I send the bytes 240 1 247, the Arduino Uno returns 248 224 and nothing else!
If I set the baud to 115200, the Arduino Uno returns the proper values.
What are you using to communicate with your Arduino? Are you using the built-in serial monitor? Whatever you are using, you must make sure to set its baud rate to match whatever you give to Serial.begin(). It sounds like you are changing the baud rate in your sketch but not in the serial monitor.
--
The Quick Shield: breakout all 28 pins to quick-connect terminals
I tested with the serial monitor, Pure Data and Processing. I also switched boards with the same code. The Duemilanove runs the code fine, the Arduino Uno does not.
Here are some more strange results (when using Arduino's serial monitor set to the proper baud rate) with the Arduino Uno and the same code:
When I type "a" (send)
I receive "a"
When I type "ab" (send)
I receive "ab"
When I type "abc" (send)
I receive "abì"
When I type "abcdefg" (send)
I receive "ab,V–"
If I switch the baud to 115200 in the code AND in the serial monitor, all the messages sent are identical to the ones received. There definitely is a problem with 57600.
That is interesting. It does have all the hallmarks of a not-quite-right-baudrate issue though. I don't suppose you have an oscilloscope that you can connect to the RXD serial line (digital pin D0) to accurately measure the bit width? It should be 17.36 microseconds.
--
The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, light sensor, potentiometers, pushbuttons
I see the same problem. I can get it to work better by commenting out the fancy code in HardwareSerial.cpp that tries to get "better" bitrates by using U2X mode...
(interestingly, the other direction seems to work fine. I don't see any errors in the byte stream sent TO my mac...)
I wrote a sketch to dump the UART config. It is using u2x mode for 57600, and it DOES seem to have correct values for the bit rate generator...
Hmm. Now that the Uno has an ATmega chip for the USB/Serial converter, is THAT firmware (LUFA) using the same algorithm for picking bitrates as the arduino firmware? This sort of thing could be explained if the 8u is picking a divisor/setting with +n% error, while the 328 is picking a divisor with -m% error... Having them MATCH is more important than actually being close to the specified bit rate...
In fact, it looks like the 8u firmware has special case code for 57600 that DOES configure its uart "opposite" the way the 328 is configured. I can't tell whether that is a bug, or something that was done specifically to address 57600bps issues with an earlier Arduino; there's a comment there about being compatible with the 57600bps bootloader on 328, but... the 328 bootloader doesn't RUN at 57600 any more. And if it is talking about the current Arduino code, it looks like the tests are backward (it picks u2x for everything except 57600 !?)
The original Arudino bootloader never tried to use the 2X mode, so it communicated at 58824 baud, not 57600. That's +2.124% error, which is just barely within 8 bit serial tolerance. In other words, all those Duemilanove boards were just barely working when in bootloader mode.
Dean probably tested the 8u2 firmware for Uno with a Duemilanove running the original bootloader at 58824 baud, instead of optiboot. Just as I encountered, if you use the "best" baud rate in 2X mode, which is 57143 (-0.794% error), then you can't communicate with the original Arduino bootloader.
What about just using this for the baud rate calculation (for Serial.begin())?
bool use_u2x = true;
#if F_CPU == 16000000UL
// hardcoded exception for compatibility with the bootloader shipped
// with the Duemilanove and previous boards and the firmware on the 8U2
// on the Uno and Mega 2560.
if (baud == 57600) {
use_u2x = false;
}
#endif
You can always tweak the baud rate to talk to a peripheral that doesn't work with the -2.1% error that this gives (the same as you get on the 8 MHz board in double-speed mode, for example). It's not clean, but I'd rather have communication with the computer work by default.
I just ran into this exact same problem when trying to run at 57600 on U21. I'm happy to report that U22 fixes the problem. Didn't realize there was an update available or I would have already upgraded, and then I would have never even known about this issue.