Locating UART and FUSES configuration file in arduino library

Hi everyone,

I am new to the forum and hope this question is not elsewhere I do not know. I have researched through the forum topics but could not find the solution yet.

I am currently testing my new board, which uses the atmega2560 and a 20Mhz external crystal. I am trying to communicate with the tera terms to check the TX/RX of the board. I only test with simple command like serial.begin(9600) through the atmel studio 7.0. However, when I use the logic analyzer, I figure out that the baud rate is actually 1.25 ratio off by my desired baud rate. For example if I the baud rate I choose is 9600, the logic analyzer claims that it is being transmitted at 12000 instead and similarly for other frequency. Therefore the tera term only works by using the 12kHz. I have done research about this problem and most of it modify the prescaler and clock source manually in the sketch file. However, I want to know how the IDE (atmel studio, arduino) configure the UART values internally since I cannot find corresponding header of cpp files that do so. I want to know how exactly those files choose clock source, prescaler and generate the baud rate correspondingly.

Like I said, I am using 20Mhz external crystal, while most of the topics I research they use 16Mhz. Is this can be a reason to above problem and how specifically (if you show me the code configuration it would be awesome). Since 20/16 = 1.25 so I think there is correlation.

Another thing is that when we configure the uart register, changing the clock and prescaler values, is it going to affect the whole system or just the uart operation only? If yes, how to avoid specifically.

Lastly, I messed up the fuse bit settings of my arduino uno atmega2560 through atmel studio tools and now the IDE cannot recognize my arduino anymore and, which prevents me to reconfigure the fuse bit. The arduino IDE also keeps saying timeout communicating with programmer. Is there anyway that I can reset the system back to normal? Also, when atmel studio set up the fuse bits, where is the find that manipulate all of the settings? I want to take a closer look to the fuse settings in code.

Thank you


If you're using 20mhz crystal, you need a new board definition (copy of the Mega entry) with cpu.speed set to 20000000 instead of 16000000 - otherwise, everything will run 25% faster than you tell it to, since everything is derived from the crystal.

Hi DrAzzy, I found the boards.txt files that defines all the parameter like F_CPU, which they assume my clock is 16Mhz. I have changed the crystal to be 16Mhz and it works perfectly. Also, I want to ask how the boards.txt communicates with the arduino IDE, compiler. It is just a text file with some commands like "yun.build.f_cpu=16000000L" which I never seen before.