Arduino Mega 2560, Baud Rate and Frenquency

Hello,

I am currently facing an issue.

I have a device (which cannot be modified) that runs at 230400 Baud.

The problem is that the Arduino Mega has a clock of 16Mhz. At this baud rate we have an error of 7.8% : WormFood's AVR Baud Rate Calculator Ver. 2.1.1

What would be solutions to modify the clock to 14.7456Mhz ?
Could it be done in the soft ?
Do I have to do add something between the device and the Serial ports ?
Do you have any other idea ?

Thank you very much,

Taz.

7.8 percent is a lot. It is marked red at wormfood, that's not good.

If you replace the crystal, then the F_CPU can be changed, and the sketch and libraries will be compiled with the new clockspeed. That should work. Although I have seen code that checks for 16MHz and 8MHz and nothing else.

The bootloader is compiled for a certain frequency. Uploading a sketch also uses a certain baudrate. You could write a custom bootloader for the new clock speed, or create a new board in boards.txt (but I don't know if a non-standard baudrate is accepted).
It is also possible to upload a sketch using a programmer (the bootloader will be removed).

The Arduino Leonardo has a spare hardware serial port and USB communication to the computer. The baudrate for the USB communication to the computer is not really used. But the board is reset with a baudrate of 1200. Perhaps it is easier for the Leonardo to run at a different speed.

What about an extra serial chip with its own special crystal ?

"Although I have seen code that checks for 16MHz and 8MHz and nothing else."
The Atmega2560 is only rated for up to 16 MHz, and 8 MHs is the speed of the internal clock. Not really much need to support other frequencies.
According to Atmega2560
Table 22-12. Examples of UBRRn Settings for Commonly Used Oscillator Frequencies
with
fosc = 16.0000MHz
and a baud rate of
230.4K,
setting U2Xn = 0 results in a UBRR of 3 and error of 8.5%
while setting U2Xn = 1 yields UBRR of 8 and error of -3.5%.

You'd have to check the Serial.h or maybe Serial.cpp (or something related to Serial) to find out what settings are really used.
If you want to pull the resonator off and install a different one, then other software changes would also be needed as noted earlier.

Interesting that the Speed Grades listed on the front page of the data sheet only go to 16MHz, while the table I referenced includes 20 MHz:
Speed Grade:
– ATmega640V/ATmega1280V/ATmega1281V:
• 0 - 4MHz @ 1.8V - 5.5V, 0 - 8MHz @ 2.7V - 5.5V
– ATmega2560V/ATmega2561V:
• 0 - 2MHz @ 1.8V - 5.5V, 0 - 8MHz @ 2.7V - 5.5V
– ATmega640/ATmega1280/ATmega1281:
• 0 - 8MHz @ 2.7V - 5.5V, 0 - 16MHz @ 4.5V - 5.5V
– ATmega2560/ATmega2561:
• 0 - 16MHz @ 4.5V - 5.5V

And the Speed Grades section only goes to 16 MHz also
31.2 Speed Grades
along with the Ordering Information
35. Ordering Information

Maybe its a carryover from the 1284P family, which is rated for 20 MHz. Or just an oversight.

Adding an SPI UART would be another option, such as:

"Baud rates up to 5 Mbit/s in 16x clock mode"

I also vote for a SPI UART. That way the Arduino stays original and can be replaced by another Arduino board.
Too bad this one is retired ! SparkFun I2C/SPI-to-UART Breakout - SC16IS750 - BOB-09981 - SparkFun Electronics

Thanks for your reply. Ordered the SPI UART module. I will let you know :slight_smile:

For anyone that finds this old topic.

The SPI UART will NOT work. Read the data sheet.

Top speed is only 38400 baud.

That's just twice the 115k baudrate, so that the double clock feature of the serial ports can be used.