Having an problem with the 14400 baud rate on an Mega Board.
With Serial1 Tx Connected to Rx the following code works on 9600 and 19200 baud rates
but on 14400 the pulse width varies from bit to bit (from 50 to 100 uSec)
Results->
Using the Serial Monitor->
sending 'r' or 'y' the return is 'r' or 'y'
sending 'R' or 'Y' the return is 'r' or 'y'
Upper case is returned as lower case
sending a string of characters return trash
again other baud rates work fine
Overall byte times @ 14400 baud>
Overall time of a byte from PC/SerialMonitor = 875 uSec
Overall time of a byte from UNO to PC/SerialMonitor = 835 uSec
The transmitted bits from the UNO are shorter than the bits from the PC
New byte times for 14400 baud:
The Uno Tx pin is high is goes low for 625 uSec then return high(the previous value was in error)
on incoming from PC the Rx is high and goes low for 725 uSec before returning high
I believe the problem is with the SERIAL_2X_UBBRVAL macro
how do you figure? The 57600bps special case was because the bootloader (which is "hard" to change) was using 57600 (as close as possible) without the "double-speed" option, while the usb/serial device was using 57600 as close as possible WITH the u2x option, and they were on opposite sides of "correct", making them far enough apart to not talk to each other (even though theoretically, each was with "allowable" tolerance WRT the actual bitrate.
The mega should talk fine to its own usb/serial port, because they should have consistently picked "which side" of 14400to be on, and other devices (most other devices) should be OK if they're closer to correct.
And I can't think of a reason why a serial port couldn't talk to itself or another serial port on the same arduino (with the same bitrate generator decisions), EVER, even if the resulting bitrate were WAY off of what was expected (it should still be the same for receiver and transmitter.)
You have point. The problem could also be in the USB handler of the ATmega8U2.
The mega should talk fine to its own usb/serial port, because they should have consistently picked "which side" of 14400to be on, and other devices (most other devices) should be OK if they're closer to correct.
I agree. But that's not the issue...
The sketch tries to set the ATmega328 baud rate to 14400. The evidence indicates that worked.
Serial Monitor tries to set the ATmega8U2 baud rate to 14400. The evidence indicates that did not work.