Permalink
Browse files

Changing baud rate calculation to always use double speed mode except…

  • Loading branch information...
1 parent 24e057a commit 66755f9bced2009612052800ef7f1a0b9afde3c5 @damellis damellis committed Nov 12, 2010
Showing with 9 additions and 15 deletions.
  1. +9 −15 hardware/arduino/cores/arduino/HardwareSerial.cpp
View
24 hardware/arduino/cores/arduino/HardwareSerial.cpp
@@ -194,22 +194,16 @@ HardwareSerial::HardwareSerial(ring_buffer *rx_buffer,
void HardwareSerial::begin(long baud)
{
uint16_t baud_setting;
- bool use_u2x;
-
- // U2X mode is needed for baud rates higher than (CPU Hz / 16)
- if (baud > F_CPU / 16) {
- use_u2x = true;
- } else {
- // figure out if U2X mode would allow for a better connection
-
- // calculate the percent difference between the baud-rate specified and
- // the real baud rate for both U2X and non-U2X mode (0-255 error percent)
- uint8_t nonu2x_baud_error = abs((int)(255-((F_CPU/(16*(((F_CPU/8/baud-1)/2)+1))*255)/baud)));
- uint8_t u2x_baud_error = abs((int)(255-((F_CPU/(8*(((F_CPU/4/baud-1)/2)+1))*255)/baud)));
-
- // prefer non-U2X mode because it handles clock skew better
- use_u2x = (nonu2x_baud_error > u2x_baud_error);
+ 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
if (use_u2x) {
*_ucsra = 1 << _u2x;

1 comment on commit 66755f9

@dreamcat4

This doesnt seem to fix the reported error. See:

http://code.google.com/p/arduino/issues/detail?id=394

Please sign in to comment.