Go Down

Topic: [Solved, sort of] Uno, 57600 baud, bad data (Read 526 times) previous topic - next topic

draythomp

Jun 13, 2011, 08:13 pm Last Edit: Jun 14, 2011, 02:51 am by draythomp Reason: 1
This little piece of code :
Code: [Select]
void setup() {
 Serial.begin(57600);
 Serial.println("just testing");
}

void loop(){
 char c;
 if (Serial.available() > 0){ // is there a character in the buffer?
   c = Serial.read();
   Serial.print("Incoming character is ");
   Serial.println(c);         //just shows the incoming character
 }
}


Doesn't work properly at 57600 baud,  Change the baud rate to anything else and it just takes off and works fine, even 115200.  If I send the Uno one character at a time, I get the character properly; if I send a line like "Hello there" I get the "He" ok and the rest is junk.  When I searched for other folks that had had this problem I noticed a bunch of them having problems with this baud rate for GPS applications, but nothing else.

What's up with this?  What am I overlooking?
Trying to keep my house under control http://www.desert-home.com/

Coding Badly


I can think of two possibilities...

1. With the processor running at 16 MHz, none of the serial port baud rates are accurate.  The error is usually tiny and insignificant.  It is possible that the error is a bit higher and significant at a baud rate of 57600.

2. This is from the core...

Quote
void HardwareSerial::begin(long baud)
{
  uint16_t baud_setting;
  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

draythomp

Dear Badly,

Thank you.  You gave me enough information to find the problem.  It wasn't me and this HAS been discussed a lot, but on the old board.  The 57600 baud rate is basically broken (at least under 021) and you can make it work by fudging the baudrate some.  I found that

  Serial.begin(58824);

made it work fine for long lines of input and such.  I'll look into this more and gather more data, but you got me over the hump.

Sigh.......
Trying to keep my house under control http://www.desert-home.com/

Coding Badly


Ding!  I remember!  Your post dug this up from my memory...

Paul Stoffregen has a nice write-up about the issue...
http://www.pjrc.com/teensy/td_uart.html

kg4wsv

IIRC, there was a problem with the UNO bootloader at 56k baud.  Rather than fix the bootloader they decided to break 56k baud for all other applications.

-j

Go Up