aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid A. Mellis <d.mellis@arduino.cc>2011-05-14 12:25:39 -0400
committerDavid A. Mellis <d.mellis@arduino.cc>2011-05-20 13:29:13 -0400
commit664e9af2cd359b6e301c43cbfd21a80f390df5f4 (patch)
tree20a2398d0189fdbfe60b79557a4bfda4f09527e7
parent90c487402cefadb6a2aab907ab07075cbb759e34 (diff)
Fixing 300 baud communication for serial.
Because UBBR is only 12 bits, we were overflowing it at 300 baud because of the use of the U2X bit. Now we turn off U2X if it would yield a UBBR value that would overflow. Note that this breaks 300 baud communication with the computer on the Uno and Mega 2560 because the 8U2 USB-serial firmware has this same bug (and previously they cancelled each other out). Since, however, it seems more likely that people will need to use 300 baud to communicate with other (legacy) hardware than with the computer, I'm making this change. Issue for 8U2 firmware bug: http://code.google.com/p/arduino/issues/detail?id=542 http://code.google.com/p/arduino/issues/detail?id=522
-rw-r--r--cores/arduino/HardwareSerial.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/cores/arduino/HardwareSerial.cpp b/cores/arduino/HardwareSerial.cpp
index d6d7b60..db6b149 100644
--- a/cores/arduino/HardwareSerial.cpp
+++ b/cores/arduino/HardwareSerial.cpp
@@ -278,6 +278,8 @@ void HardwareSerial::begin(unsigned long baud)
use_u2x = false;
}
#endif
+
+try_again:
if (use_u2x) {
*_ucsra = 1 << _u2x;
@@ -286,6 +288,12 @@ void HardwareSerial::begin(unsigned long baud)
*_ucsra = 0;
baud_setting = (F_CPU / 8 / baud - 1) / 2;
}
+
+ if ((baud_setting > 4095) && use_u2x)
+ {
+ use_u2x = false;
+ goto try_again;
+ }
// assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
*_ubrrh = baud_setting >> 8;