Skip to content

Commit 2711c99

Browse files
committed
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
1 parent a98816a commit 2711c99

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

hardware/arduino/cores/arduino/HardwareSerial.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ void HardwareSerial::begin(unsigned long baud)
278278
use_u2x = false;
279279
}
280280
#endif
281+
282+
try_again:
281283

282284
if (use_u2x) {
283285
*_ucsra = 1 << _u2x;
@@ -286,6 +288,12 @@ void HardwareSerial::begin(unsigned long baud)
286288
*_ucsra = 0;
287289
baud_setting = (F_CPU / 8 / baud - 1) / 2;
288290
}
291+
292+
if ((baud_setting > 4095) && use_u2x)
293+
{
294+
use_u2x = false;
295+
goto try_again;
296+
}
289297

290298
// assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
291299
*_ubrrh = baud_setting >> 8;

0 commit comments

Comments
 (0)