Burn firmware on atmega 16u2 as USB for atmega2560

I'm trying to use a standalone atmega2560 and I'm using a mega 16u2 to make it communicate via USB. I'm correctly able to upload sketch by using the "upload with a programmer" feature with an additional atmega2560 board and by using the ICSP connector.
Now, I would like to use the 16u2 chip in order to directly upload the sketches to the atmega2560.
Since the 16u2 is blank, I need to upload a firmware for it.

I'm following this tutorial: Arduino - Upgrading16U2Due
to burn the firmware on my atmega16u2 that should work as USB for the atmega2560.

I tried to upload it with:

avrdude.exe -C avrdude.conf -c arduino -P COM9 -b 19200 -p m16u2 -vvv -U flash:w:Arduino-usbserial-atmega16u2-Mega2560-Rev3.hex:i

with this result:

avrdude.exe: Version 6.3, compiled on Feb 17 2016 at 09:25:53
             Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
             Copyright (c) 2007-2014 Joerg Wunsch

             System wide configuration file is "avrdude.conf"

             Using Port                    : COM9
             Using Programmer              : arduino
             Overriding Baud Rate          : 19200
avrdude.exe: ser_recv(): programmer is not responding
avrdude.exe: stk500_recv(): programmer is not responding
avrdude.exe: stk500_getsync() attempt 1 of 10: not in sync: resp=0x34
             AVR Part                      : ATmega16U2
             Chip Erase delay              : 9000 us
             PAGEL                         : PD7
             BS2                           : PC6
             RESET disposition             : possible i/o
             RETRY pulse                   : SCK
             serial program mode           : yes
             parallel program mode         : yes
             Timeout                       : 200
             StabDelay                     : 100
             CmdexeDelay                   : 25
             SyncLoops                     : 32
             ByteDelay                     : 0
             PollIndex                     : 3
             PollValue                     : 0x53
             Memory Detail                 :

                                      Block Poll               Page                       Polled
               Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
               ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
               eeprom        65    20     4    0 no        512    4    128  9000  9000 0x00 0x00
                                      Block Poll               Page                       Polled
               Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
               ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
               flash         65     6   128    0 yes     16384  128    128  4500  4500 0x00 0x00
                                      Block Poll               Page                       Polled
               Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
               ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
               lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
                                      Block Poll               Page                       Polled
               Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
               ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
               hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
                                      Block Poll               Page                       Polled
               Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
               ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
               efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
                                      Block Poll               Page                       Polled
               Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
               ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
               lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
                                      Block Poll               Page                       Polled
               Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
               ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
               calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
                                      Block Poll               Page                       Polled
               Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
               ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
               signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

             Programmer Type : Arduino
             Description     : Arduino
             Hardware Version: 2
             Firmware Version: 1.18
             Topcard         : Unknown
             Vtarget         : 0.0 V
             Varef           : 0.0 V
             Oscillator      : Off
             SCK period      : 0.1 us

avrdude.exe: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude.exe: Device signature = 0x1e9489 (probably m16u2)
avrdude.exe: safemode read 1, lfuse value: 5e
avrdude.exe: safemode read 2, lfuse value: 5e
avrdude.exe: safemode read 3, lfuse value: 5e
avrdude.exe: safemode: lfuse reads as 5E
avrdude.exe: safemode read 1, hfuse value: d9
avrdude.exe: safemode read 2, hfuse value: d9
avrdude.exe: safemode read 3, hfuse value: d9
avrdude.exe: safemode: hfuse reads as D9
avrdude.exe: safemode read 1, efuse value: f4
avrdude.exe: safemode read 2, efuse value: f4
avrdude.exe: safemode read 3, efuse value: f4
avrdude.exe: safemode: efuse reads as F4
avrdude.exe: NOTE: "flash" memory has been specified, an erase cycle will be performed
             To disable this feature, specify the -D option.
avrdude.exe: erasing chip
avrdude.exe: reading input file "16u2.hex"
avrdude.exe: writing flash (4034 bytes):

Writing | ################################################## | 100% 4.59s

avrdude.exe: 4034 bytes of flash written
avrdude.exe: verifying flash memory against 16u2.hex:
avrdude.exe: load data flash data from input file 16u2.hex:
avrdude.exe: input file 16u2.hex contains 4034 bytes
avrdude.exe: reading on-chip flash data:

Reading | ################################################## | 100% 2.62s

avrdude.exe: avr_read(): skipping page 32: no interesting data
avrdude.exe: avr_read(): skipping page 33: no interesting data
avrdude.exe: avr_read(): skipping page 34: no interesting data
avrdude.exe: avr_read(): skipping page 35: no interesting data
avrdude.exe: avr_read(): skipping page 36: no interesting data
avrdude.exe: avr_read(): skipping page 37: no interesting data
avrdude.exe: avr_read(): skipping page 38: no interesting data
avrdude.exe: avr_read(): skipping page 39: no interesting data
avrdude.exe: avr_read(): skipping page 40: no interesting data
avrdude.exe: avr_read(): skipping page 41: no interesting data
avrdude.exe: avr_read(): skipping page 42: no interesting data
avrdude.exe: avr_read(): skipping page 43: no interesting data
avrdude.exe: avr_read(): skipping page 44: no interesting data
avrdude.exe: avr_read(): skipping page 45: no interesting data
avrdude.exe: avr_read(): skipping page 46: no interesting data
avrdude.exe: avr_read(): skipping page 47: no interesting data
avrdude.exe: avr_read(): skipping page 48: no interesting data
avrdude.exe: avr_read(): skipping page 49: no interesting data
avrdude.exe: avr_read(): skipping page 50: no interesting data
avrdude.exe: avr_read(): skipping page 51: no interesting data
avrdude.exe: avr_read(): skipping page 52: no interesting data
avrdude.exe: avr_read(): skipping page 53: no interesting data
avrdude.exe: avr_read(): skipping page 54: no interesting data
avrdude.exe: avr_read(): skipping page 55: no interesting data
avrdude.exe: avr_read(): skipping page 56: no interesting data
avrdude.exe: avr_read(): skipping page 57: no interesting data
avrdude.exe: avr_read(): skipping page 58: no interesting data
avrdude.exe: avr_read(): skipping page 59: no interesting data
avrdude.exe: avr_read(): skipping page 60: no interesting data
avrdude.exe: avr_read(): skipping page 61: no interesting data
avrdude.exe: avr_read(): skipping page 62: no interesting data
avrdude.exe: avr_read(): skipping page 63: no interesting data
avrdude.exe: avr_read(): skipping page 64: no interesting data
avrdude.exe: avr_read(): skipping page 65: no interesting data
avrdude.exe: avr_read(): skipping page 66: no interesting data
avrdude.exe: avr_read(): skipping page 67: no interesting data
avrdude.exe: avr_read(): skipping page 68: no interesting data
avrdude.exe: avr_read(): skipping page 69: no interesting data
avrdude.exe: avr_read(): skipping page 70: no interesting data
avrdude.exe: avr_read(): skipping page 71: no interesting data
avrdude.exe: avr_read(): skipping page 72: no interesting data
avrdude.exe: avr_read(): skipping page 73: no interesting data
avrdude.exe: avr_read(): skipping page 74: no interesting data
avrdude.exe: avr_read(): skipping page 75: no interesting data
avrdude.exe: avr_read(): skipping page 76: no interesting data
avrdude.exe: avr_read(): skipping page 77: no interesting data
avrdude.exe: avr_read(): skipping page 78: no interesting data
avrdude.exe: avr_read(): skipping page 79: no interesting data
avrdude.exe: avr_read(): skipping page 80: no interesting data
avrdude.exe: avr_read(): skipping page 81: no interesting data
avrdude.exe: avr_read(): skipping page 82: no interesting data
avrdude.exe: avr_read(): skipping page 83: no interesting data
avrdude.exe: avr_read(): skipping page 84: no interesting data
avrdude.exe: avr_read(): skipping page 85: no interesting data
avrdude.exe: avr_read(): skipping page 86: no interesting data
avrdude.exe: avr_read(): skipping page 87: no interesting data
avrdude.exe: avr_read(): skipping page 88: no interesting data
avrdude.exe: avr_read(): skipping page 89: no interesting data
avrdude.exe: avr_read(): skipping page 90: no interesting data
avrdude.exe: avr_read(): skipping page 91: no interesting data
avrdude.exe: avr_read(): skipping page 92: no interesting data
avrdude.exe: avr_read(): skipping page 93: no interesting data
avrdude.exe: avr_read(): skipping page 94: no interesting data
avrdude.exe: avr_read(): skipping page 95: no interesting data
avrdude.exe: avr_read(): skipping page 96: no interesting data
avrdude.exe: avr_read(): skipping page 97: no interesting data
avrdude.exe: avr_read(): skipping page 98: no interesting data
avrdude.exe: avr_read(): skipping page 99: no interesting data
avrdude.exe: avr_read(): skipping page 100: no interesting data
avrdude.exe: avr_read(): skipping page 101: no interesting data
avrdude.exe: avr_read(): skipping page 102: no interesting data
avrdude.exe: avr_read(): skipping page 103: no interesting data
avrdude.exe: avr_read(): skipping page 104: no interesting data
avrdude.exe: avr_read(): skipping page 105: no interesting data
avrdude.exe: avr_read(): skipping page 106: no interesting data
avrdude.exe: avr_read(): skipping page 107: no interesting data
avrdude.exe: avr_read(): skipping page 108: no interesting data
avrdude.exe: avr_read(): skipping page 109: no interesting data
avrdude.exe: avr_read(): skipping page 110: no interesting data
avrdude.exe: avr_read(): skipping page 111: no interesting data
avrdude.exe: avr_read(): skipping page 112: no interesting data
avrdude.exe: avr_read(): skipping page 113: no interesting data
avrdude.exe: avr_read(): skipping page 114: no interesting data
avrdude.exe: avr_read(): skipping page 115: no interesting data
avrdude.exe: avr_read(): skipping page 116: no interesting data
avrdude.exe: avr_read(): skipping page 117: no interesting data
avrdude.exe: avr_read(): skipping page 118: no interesting data
avrdude.exe: avr_read(): skipping page 119: no interesting data
avrdude.exe: avr_read(): skipping page 120: no interesting data
avrdude.exe: avr_read(): skipping page 121: no interesting data
avrdude.exe: avr_read(): skipping page 122: no interesting data
avrdude.exe: avr_read(): skipping page 123: no interesting data
avrdude.exe: avr_read(): skipping page 124: no interesting data
avrdude.exe: avr_read(): skipping page 125: no interesting data
avrdude.exe: avr_read(): skipping page 126: no interesting data
avrdude.exe: avr_read(): skipping page 127: no interesting data
avrdude.exe: verifying ...
avrdude.exe: 4034 bytes of flash verified

avrdude.exe: safemode read 1, lfuse value: 5e
avrdude.exe: safemode read 2, lfuse value: 5e
avrdude.exe: safemode read 3, lfuse value: 5e
avrdude.exe: safemode: lfuse reads as 5E
avrdude.exe: safemode read 1, hfuse value: d9
avrdude.exe: safemode read 2, hfuse value: d9
avrdude.exe: safemode read 3, hfuse value: d9
avrdude.exe: safemode: hfuse reads as D9
avrdude.exe: safemode read 1, efuse value: f4
avrdude.exe: safemode read 2, efuse value: f4
avrdude.exe: safemode read 3, efuse value: f4
avrdude.exe: safemode: efuse reads as F4
avrdude.exe: safemode: Fuses OK (E:F4, H:D9, L:5E)

avrdude.exe done.  Thank you.

It worked fine and if I connect the USB to my pc I can recognize the board as atmega2560.
However, if I try to upload a sample sketch by using the Arduino IDE, I get this error:

stk500v2_receivemessage() timeout
ser_send() write error sorry no info avail

may be I uploaded a wrong firmware?
the chip is ATMEL mega 16u2 2117

1 Like

This is a bit outside my knowledge. Did you wire the reset of the 2560 to the CTS line of the 16U2? The relevant part of the schematic of the Mega

Another thing might be if anything is connected to the RX and TX pins of the Mega.

This is my circuit:

I tried to upload a simple sketch on the atmega2560 that prints "Hello world" on the serial TX and RX and then I tried to read the output through the USB port connected to the mega 16u2 but I can only see garbage chars even if I correctly set the baud rate.

However, the atmega2560 is OK since I can program it without problems, I think the problem should be with the firmware I uploaded on the 16u2 or may be in the circuit?

Please, try to help me! I really don't know how to solve!

I tried to upload different firmware, but I had no success to make it work to upload sketch directly on the atmega2560.

I can correctly read and send data over the USB to the atmega, so the serial communication is working fine, but I can't use Arduino IDE to directly upload sketches to the atmega2560.

Still no success with the possibility to upload sketches to the atmega6 by using the USB connection on the atmega16u2!

I can use the atmega16u2 to read and write data from the atmega2560, but it fails when I try to upload a sketch and I always have to use the "upload sketch using programmer" option when I want to load a new sketch.

Since I'm able to communicate with the 16u2, I think the circuit is fine, is it correct?