[SOLVED] UNO R3 with Atmega1284P 20MHz unable upload sketch

I am trying Atmega1284P MCU connected to Arduino UNO R3 board without MCU using optiboot. It works fine on 16MHz but on 20MHz is unable to upload sketch. Bootloader for 20MHz seems to be worked also at start (according LED flashes). It looks like some UART communication problem between Atmega1284P and UNO R3 board. Any advice?

Did you recompile a version of optiboot designed for the 20MHz clock rate? If you have the 16MHz optiboot in there, it's going to be running at (hmm) 144000bps instead of 115200bps. There isn't any way for the code to know the actual clock rate, and the serial speed is just some divided-down version of the system clock.

(if you run ArduinoISP on your Uno and connect to your 1284p via SPI instead of serial, then the serial port rate won't matter, and it should work fine.)

I am using different versions of bootloader: 16 MHz and 20MHz. Upload at 115200bps for both. I could try different speeds...

(if you run ArduinoISP on your Uno and connect to your 1284p via SPI instead of serial, then the serial port rate won't matter, and it should work fine.)

Yes! There is no problem to load bootloader 20 or 16 Mhz version.

I haven't actually tested optiboot on a 1284 at 20MHz, but there's no reason that it shouldn't work. What steps did you take to compile the 20MHz bootloader?

I used the same way for compiling just different frequency parameter. Yesterday I tried to change upload speed.
I tested several speeds without any success. Everything what I did is to change bootloader and crystal - 16MHz works, 20MHz not.

Does anybody try to use same combination UNO R3 (without MCU) and ATmega1284P?

Problem SOLVED! :D For anyone who has the same problem. After many experiments I found out finally that the problem is caused by UART error drift because ATmega crystal frequency not perfectly fit for UART speed except some cases (18,432MHz e.g.). The trick is to keep this error as close to zero as possible, but under 2%. Arduino boards use ATmega16U2 with 16MHz it cause error 2,1% at upload speed 115200bps which Arduino UNO R3 uses by default. If the main MCU is running on 16MHz, has the same error which compensate with ATmega16U2 error. However, in case of 20MHz the error is -1,4%, total error is 3,5% and there is a problem to upload sketch because ATmegas can't communicate together. The solution is for example to choose upload speed at 57600baud with an error 0,9% (in the same direction as ATmega16U2) , total error is now 1,2% (less than 2%) and...voalaa, no problem to upload. :grin: :grin: :grin: :grin: