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: https://www.arduino.cc/en/Hacking/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?

Hi @marcusbarnet any luck with this? I am literally in the same position. I have a working mega 2560 which I can upload sketches using a programmer in IDE but I still haven't worked out why I can't get the 16u2 to communicate with the 2560.

Reading through the posts, there's a couple of things that weren't clear (or maybe I just missed them):

  1. Was a bootloader loaded into the 2560?
  2. If a bootloader was loaded into the 2560, which UART was it configured for?

From the link in post #1, it seems that the 16u2 is simply acting as a USB-Serial adapter. You need a bootloader in the 2560 configured to work with the UART port that the 16u2 is connected to.

Hi @markd833

  1. Yes a bootloader was uploaded to the 2560. this was done Using an arduino UNO as the ISP and burning a bootloader for a MEGA 2560 through Arduino IDE.

  2. I assume the Arduino MEGA 2560 bootloader uploaded the UART configuration to use PE0 and PE1 on the ATMEGA256-AU to communicate with the 16U2 on PD2 and PD3. My PCB has the same communication pathway as the standard Arduino MEGA 2560. So I don't see any issues here.

That is correct. The 16U2 is a USB-serial interface between a PC (arduino IDE) and the MEGA 2560.

A few other thoughts in case you've not already tried:

If you short PD2 to PD3 on the 16u2 and using something like the IDE serial monitor, send some characters to the 16u2, do you see them echoed back? This test is detailed here for a standard board:

That should check that your 16u2 is behaving.

If that is successful, the I'd upload a sketch into the 2560 via the UNO as ISP route that simply printed a phrase to the serial port and then echoed back any characters received. That should test the serial connection between the 2560 and the 16u2.

If that works ok, then I'd be looking at the circuity associated with the resetting of the 2560 from the 16u2.

Don't forget to burn the bootloader back onto the 2560 after this test, uploading a sketch using the ISP connection erases the bootloader.

So i figured it out. You have to manually push the reset button just after to click upload. The question is why am i having to do this. On a standard arduino even if a loop and traffic in the serial monitor if you upload a new sketch it would auto reset it for you and upload a new sketch.

Any ideas?

There must be a connection between DTR of the 16U2 and the reset pin of the main processor to invoke the boot loader.

Looking at the schematic for the Arduino 2560 board, there is a link from the 16u2 PD7 via a 100n onto the 2560 RESET pin. There's also a 1K to GND on the 16u2 side of the 100n.

You need this or the equivalent to allow the 16u2 to reset the 2560 as part of the sketch loading process - i.e. the bit you are having to do manually with the reset button.

Aaaaa... very nice. I see what i have done. Without realizing i have put on a 22 resistor instead of a 1k. I will look to remove it and install a new one this weekend

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.