Atmega2560 + Atmega16u2 startup problem

Hi everyone,

I'm working on device that is using AtMega2560 as main microcontroller and AtMega16u2 as USB/Serial converter. This is identical as can be found in Arduino Mega R3 (including bootloader).

When I connect device to PC, wait few seconds and open Serial communication everything works great.
Problem occurs when I open Serial communication and start sending data immediately after powering on microcontroller. In this situation AtMega2560 prevents to start.
I know that this is happening because AtMega2560 bootloader waits if there is new sketch waiting to be uploaded to it.

Is there any solution to force AtMega2560 to start even if it starts receiving serial data immediately after powering? Maybe modifying firmware of Atmega16u2 ?

Do you need the bootloader? If you connect an ISP programmer to your ATmega2560 and do a Sketch > Upload Using Programmer then your uploaded program will overwrite the bootloader. Of course then you can't do uploads via serial.

How "immediately" do you really need to start sending data? I believe the optiboot bootloader has a shorter delay after startup than the standard bootloader used on the Arduino Mega. You can easily install optiboot on your board using this hardware package:

Hi pert,

thanks for your suggestion.
It will be helpful to have bootlader so I can easily upload new sketch using USB. But it is not essential.

Host machine always send data, it can happen in 300ms or 10ms, you never know.

I changed high fuse to D9 and uploaded sketch using USBASP and know arduino boot immediately and doesn't lock on startup.

mega.menu.cpu.atmega2560.bootloader.high_fuses=0xD9

It is working, thanks pert :slight_smile: