The Arduino bootloader uses a specific baud rate for communication between the bootloader and the PC. The current baud rate used is 115200 baud for uploading programs. Previous bootloaders used a baud rate of 57600 baud. This baud rate is set as part of the bootloader code. When you reset the Arduino, the bootloader sets the UART to the known upload baud rate, and waits briefly for the PC to begin uploading. If an upload does not begin, the bootloader jumps to the currently loaded application program.
THE PROBLEM
The new bootloader, ready on all the latest Arduino boards, writes the firmware faster. This is great and I really like it but sometimes I got errors during the loading phase.
Sometimes I even got two consecutive errors and other times I ran hundreds of compilations and writes without errors. So in the past, like everyone else, I blamed low-quality boards, USB cables too long, too much speed, defects in the USB hubs, defects in the FTDI and CH340 drivers, etc.
Lately I have been working on the Theremino_Tester, a very demanding sketch:
" Applicazioni varie | theremino "
I had chosen 115200 as the communication speed, to conform to the new Arduino BootLoader practice already in use. But soon I started to notice errors in the serial communication. On some PCs, they never occurred, but on others they were so frequent as to be annoying.
And since the Theremino_Tester is a very useful and interesting project, I decided to seriously investigate the problem.
And I discovered that errors only occur with 115200 bps speed, and counterintuitively, the errors disappear when the speed is increased to 250k, 500k or 1M bps.
The explanation, once found, is simple. On the ATmega 328p, which has a 16 MHz clock, the speed of 115200 has a deviation of 3.5%, while 250k, 500k and 1M are free from any discrepancy (0%). You might think that 3.5% is not much, but you have to take into account that the bits accumulate one after the other and that when you get to the stop bit you are already at a percentage of 35%. A percentage that all the texts regarding serial considered unacceptable.
In the following messages, you will find detailed tables and explanations that demonstrate my thesis.
SOME WEB MESSAGES
...most of the arduino communications is between the arduino and the PC via that serial/usb chip on the board, so even if the bitrates are FAR off, you'll still get reliable communications as long as the serial/usb chip (on uno, ALSO an AVR running at 16MHz) both err in the same direction. (some of the problems that have occurred have been because the 8u2 and the 328 used DIFFERENT algorithms for picking the divisors, so that one ran +3% and the other ran -2.8%, which is not so good. (and while 115200bps is a common "fastest" speed for PCs, it's a particularly bad speed for a 16MHz AVR. Sigh.)
" How does arduino handle usart with 16MHz? - #8 by westfw "
..16MHz (default on most arduino) gives 3.7% error, which usually is too much for the other side to work without error correction.
" 115200 baud problems - #5 by mellis "
" https://wormfood.net/avrbaudcalc.php "
.... well, like dgtl said, there's 3.5% error. If the thing you are connecting to is exactly correct, or slightly incorrect in the same direction, it will probably work. You can get a -2.1% error by using the "double speed mode" (U2X0 in UART_SRA0). Note that this error is in the opposite direction of the normal calculation; I think you can be almost certain of errors if you have one AVR set one way (-2.1%), and the other set the other way (+3.5%) (5.6% total error.)
....
FTDI states in appnote, that the baud rate error should be below 3%. So running AVR at 16MHz connected to FTDI is outside allowed tolerances on both sides (assuming FTDI is spot on; they have fractional baud rate divisor so the error should be much lower but I did not care to calculate the actual numbers). Even if it seems to work at first, you can not be sure that in the whole temperature range and by using randomly selected chips at production it would still work.
....
Better select another baud rate!
Why not 250k or 500k with a 0% error?
....
" UART 115200 on ATmega328p@16Mz - Page 1 "
" https://www.eevblog.com/forum/microcontrollers/uart-115200-on-atmega328p16mz/?action=dlattach;attach=127519;image "
CONCLUSIONS
Choosing a 115200 baud rate for the new 168p bootloader was a really unfortunate choice. To make matters worse, it doesn't create enough errors to make it noticeable. If the errors were more frequent, the problem would be obvious and it would have been solved quickly. Instead, the errors are so rare that many people believe everything is ok.
But it's not "ok", the new 168p bootloader is working at the limits of acceptable and in some extreme cases the errors can become really annoying. I have a perfectly working Nano board that on some tablets causes really frequent errors, every 100-200 characters or sometimes even more often.
The extreme cases happen when the speed deviation of the Arduino board and the terminal (PC) act in opposite directions and we reach intolerable differential speed deviation, even of 5.6% and more.
But with a baud rate of 250k, 500k or 1M, the speed error is zero. I have written a dedicated sketch and a PC control application and left them running for hours. On none of the Arduino modules I have tested, and none of the tablets and PCs we use, a single error has ever occurred!
As a counter test I did the same tests at 115200 and observed frequent errors in almost all combinations of modules and PCs.
What to do now?
Naturally, I could modify the bootloader and reprogram my modules, but this would not solve the annoyance that these errors are causing to many other people.
The best solution is to convince Arduino programmers that there is a problem. We must emphasize how these upload phase errors are causing trouble to a large number of users. Even if they try to blame the issue on Chinese clones, long cables, wrong settings, user inexperience or even San Gennaro, we must stay united to make them face the problem. If many of us report these errors, they might be convinced to address them.
Those who are not affected by the issue might underestimate it, but if you experience occasional errors during the upload phase on a 328p with the new bootloader, let us know your experience and how frustrating it can be!
A SIMPLE ERROR TESTER
void setup()
{
Serial.begin(115200);
String s = " ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (int i = 0; i < 1000; i++)
{
Serial.println(String(i) + s + s);
}
}
EXAMPLE WITH ERRORS
...
omissis
...
177 ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
178 ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHI⸮)⸮⸮⸮
%5EUeu⸮⸮⸮⸮
179 ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
180 ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
181 ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
182 ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
183 ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
184 ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
185 ABCDEFGHIJKLMNOPQRSTU⸮⸮⸮
!%)-159=AEIMQUY]aei5
186 ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSU⸮⸮⸮⸮⸮
187 ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
...
omissis
...
517 ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
518 ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
⸮S⸮
!%)-159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