Mega2560 board upload fails

Hi All!
I have more MEGA boards with the same problem:

  • the windows recognizes the board as "Arduino Mega 2560" in device manager.
  • by uploading the avrdude stops with timeout failure

C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega2560 -cwiring -PCOM6 -b115200 -D -Uflash:w:C:\Users\horne\AppData\Local\Temp\arduino_build_543613/BeadSorter.ino.hex:i

avrdude: Version 6.3-20190619
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch

     System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

     Using Port                    : COM6
     Using Programmer              : wiring
     Overriding Baud Rate          : 115200

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer

  • The USB ports and the cables surely have no problem, I can upload to normally working boards with this set.
  • I can program the board with an UNO as programmer, and it works perfectly.
  • I set the board to DFU mode, and they were visible as AT90USB82, using Flip I uploaded the Arduino-usbserial-atmega16u2-Mega2560-Rev3.hex. The upload was successful, after reset the board is visible as Arduino Mega 2560 again.
  • Actually a Merlin 3d printer program is on the board, which sends info via the usb port on 250000 baudrate on serial monitor.

... but I still can't upload anything with the usb port. Why?

It's quite often something the setup tools tab.
Ports can sometimes get in a tangle even if they show OK.
Have you tried connecting and reconnecting and getting the familiar Windows com port connection jingle?
Also try restarting the computer.
And avoid USB hubs until proven OK

Unfortunately not. I tried all ports, tried restarting the pc too.

Do you mean you used the Uno as an "Arduino as ISP" programmer to do an Upload Using Programmer? If so, when you did that you erased the bootloader. This error is normal and expected when attempting to upload to a board without a bootloader. You need to connect the Uno back up as an "Arduino as ISP" and do a Tools > Burn Bootloader to restore the bootloader. After that, you will be able to upload to the Mega normally via the USB cable once more.

Thank you in0, but...
I uploaded a new bootloader as you advised:

C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega2560 -cstk500v1 -PCOM3 -b19200 -e -Ulock:w:0x3F:m -Uefuse:w:0xFD:m -Uhfuse:w:0xD8:m -Ulfuse:w:0xFF:m 

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM3
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega2560
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PA0
         RESET disposition             : dedicated
         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    10     8    0 no       4096    8      0  9000  9000 0x00 0x00
           flash         65    10   256    0 yes    262144  256   1024  4500  4500 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : STK500
         Description     : Atmel STK500 Version 1.x firmware
         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: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e9801 (probably m2560)
avrdude: erasing chip
avrdude: reading input file "0x3F"
avrdude: writing lock (1 bytes):

C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega2560 -cstk500v1 -PCOM3 -b19200 -Uflash:w:C:\Program Files (x86)\Arduino\hardware\arduino\avr/bootloaders/stk500v2/stk500boot_v2_mega2560.hex:i -Ulock:w:0x0F:m 
Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of lock written
avrdude: verifying lock memory against 0x3F:
avrdude: load data lock data from input file 0x3F:
avrdude: input file 0x3F contains 1 bytes
avrdude: reading on-chip lock data:

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

avrdude: verifying ...
avrdude: 1 bytes of lock verified
avrdude: reading input file "0xFD"
avrdude: writing efuse (1 bytes):

Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0xFD:
avrdude: load data efuse data from input file 0xFD:
avrdude: input file 0xFD contains 1 bytes
avrdude: reading on-chip efuse data:

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

avrdude: verifying ...
avrdude: 1 bytes of efuse verified
avrdude: reading input file "0xD8"
avrdude: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0xD8:
avrdude: load data hfuse data from input file 0xD8:
avrdude: input file 0xD8 contains 1 bytes
avrdude: reading on-chip hfuse data:

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

avrdude: verifying ...
avrdude: 1 bytes of hfuse verified
avrdude: reading input file "0xFF"
avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xFF:
avrdude: load data lfuse data from input file 0xFF:
avrdude: input file 0xFF contains 1 bytes
avrdude: reading on-chip lfuse data:

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

avrdude: verifying ...
avrdude: 1 bytes of lfuse verified

avrdude done.  Thank you.


avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM3
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega2560
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PA0
         RESET disposition             : dedicated
         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    10     8    0 no       4096    8      0  9000  9000 0x00 0x00
           flash         65    10   256    0 yes    262144  256   1024  4500  4500 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : STK500
         Description     : Atmel STK500 Version 1.x firmware
         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: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e9801 (probably m2560)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "C:\Program Files (x86)\Arduino\hardware\arduino\avr/bootloaders/stk500v2/stk500boot_v2_mega2560.hex"
avrdude: writing flash (261406 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 261406 bytes of flash written
avrdude: verifying flash memory against C:\Program Files (x86)\Arduino\hardware\arduino\avr/bootloaders/stk500v2/stk500boot_v2_mega2560.hex:
avrdude: load data flash data from input file C:\Program Files (x86)\Arduino\hardware\arduino\avr/bootloaders/stk500v2/stk500boot_v2_mega2560.hex:
avrdude: input file C:\Program Files (x86)\Arduino\hardware\arduino\avr/bootloaders/stk500v2/stk500boot_v2_mega2560.hex contains 261406 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 261406 bytes of flash verified
avrdude: reading input file "0x0F"
avrdude: writing lock (1 bytes):

Writing | ################################################## | 100% 0.02s

avrdude: 1 bytes of lock written
avrdude: verifying lock memory against 0x0F:
avrdude: load data lock data from input file 0x0F:
avrdude: input file 0x0F contains 1 bytes
avrdude: reading on-chip lock data:

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

avrdude: verifying ...
avrdude: 1 bytes of lock verified

avrdude done.  Thank you.

So it seems to be ok. I removed the wires, plugged the mega, changed the port, and the programmer to AVR ISP, and tried to upload the blink:

A vázlat 1536 bájt (0%)-ot használ a program tárhelyből. A maximum 253952 bájt.
A globális változók 9 bájt (0%)-ot használnak a dinamikus memóriából, 8183 bájtot hagyva a helyi változóknak. A maximum 8192 bájt.
C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega2560 -cwiring -PCOM9 -b115200 -D -Uflash:w:C:\Users\horne\AppData\Local\Temp\arduino_build_931162/Blink.ino.hex:i 

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM9
         Using Programmer              : wiring
         Overriding Baud Rate          : 115200
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer

avrdude done.  Thank you.

Hiba történt a vázlat feltöltése közben

So it is still not working :frowning:

Do you have anything connected to the Mega (e.g., shields, wiring, modules, a 3D printer)? If so, try disconnecting everything from the board and then uploading to just the board by itself.

No, there is nothing on it.

OK, so the next thing I would suggest is the loopback test. This will check the functionality of the ATmega16U2 chip used as the USB to serial adapter on the board. The fact that you were able to flash the firmware on that chip already shows it is working fairly well, but the loopback test is easy enough to run and will provide additional verification

Here are the loopback test instructions:

  1. Disconnect power from the board.
  2. Remove all connections and shields from the Arduino board.
  3. Connect a jumper wire from the RESET to the GND pin.
    (This is done to hold the primary microcontroller in a reset state so it doesn't interfere with this test of the USB to serial adapter chip on the board)
  4. Connect a jumper from the RX pin (Arduino pin 0) to the TX pin (Arduino pin 1).
  5. Connect the Arduino board to your computer.
  6. Select the port of your board from the Arduino IDE's Tools > Port menu.
  7. Select Tools > Serial Monitor from the Arduino IDE's menus.
  8. Type some text into the input field at the top of the Serial Monitor window.
  9. Press Enter.
    • If the text you typed is shown in Serial Monitor's output window, the loopback test passed :grinning:.
    • If the text was not shown, the loopback test failed :cry:.
  10. Close Serial Monitor.
  11. Disconnect the board from the computer.
  12. Remove the two jumper wires.

The text wasn't shown on serial monitor :frowning: The RX led blinked for a short or a bit longer depending on the text length I typed in.

OK, so this tell us:

The ATmega16U2 is receiving data from the computer

There is a failure somewhere in this pipeline:

  1. Conversion of the received USB data to serial
  2. Output of the signal on the ATmega16U2's TX pin
  3. Solder joint between the pin and the pad on the Mega's PCB
  4. Traces on the Mega's PCB
  5. Solder joint between the plated through hole on the Mega's PCB and the RX0 pin on the header
  6. Contact between the RX0 pin on the header and the jumper wire.
  7. Jumper wire.
  8. Contact between the jumper wire and the TX1 pin on the header.
  9. Solder joint between the TX1 pin on the header and the plated through hole on the Mega's PCB.
  10. Traces on the Mega's PCB
  11. Solder joint between pad on the Mega's PCB and the ATmega16U2's RX pin
  12. Read of the signal on the pin.

You know it got as far as (1) because of the RX LED blink and I believe if it had gotten any farther than (12) then you would have seen the TX LED blink.

The easy part of the pipeline to check is the jumper wire continuity. They do sometimes get internal breaks so it is worth a quick check either of the wire or swapping in another one.

I made some measurements.
I checked the schematic via Arduino Mega 2560 - EasyEDA open source hardware lab
The signal comes out on M8RXD pin with 5Vpp. On the other pole of the resistor RN7.2 it is still present, but with 0.5Vpp only. It goes further through everything you mentioned, and returns to the RN7.1, and to the MEGA16U2 with the same 0.5Vpp voltage level.
I checked the resistor network, all elements are 1kOhm as needed, but I haven't soldered it out so there might be some problem with it. Anyway, I think the problem will be this low voltage.

Great work! No surprise that the problematic part of the circuit would be the one I forgot on my list.

I have soldered a 1k resistor paralel to RN7.2. The loopback test works now perfectly.
The upload still doesn't work. I re-uploaded the bootloader, but it did not help, there is something more.

I am having the same problem with IDE 1.8.19 /15. It started giving upload errors, and finally permanently upload fails. Board is Mega2560. Board and port have been verified many times.

  • Three other Mega2560 boards two out of the box and one a CH340 show exactly the same problem. Avrdude fails Stk500. Sync failure or timeout failure.
  • Arduino IDE 2.0 has no issues and uploads sketches.
  • Serial communication works in IDE 1.8.19 and I can send and receive via Serial Monitor.
  • Same problem (programmer not responding, not in sync) trying to upload to an Uno.

Could this be a baud rate problem? This issue began when the sketch was going awry due to bugs in the code. But this is only on one Mega board. The other three Mega2560 boards never ran the code. So it can't be bootloader. Maybe Avrdude detected an issue with the board while it was running the problem code, and changed something permanently in conf, or in the Windows port setup (which driver has been re-installed).

  • re-installed IDE 1.8.19 and 15.
  • rebooted PC Windows 7,
  • re-installed USB drivers,
  • reset port to default in Device Manager, it reads 9600, 8, None, 1, None
  • changed USB cables (both the USB-B and the micro-USB).
  • Nothing connected to the board pins on any of the 4 boards.
  • The loopback test is successful.
C:\Users\Taler\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude -CC:\Users\Taler\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf -v -V -patmega1280 -carduino -PCOM22 -b57600 -D -Uflash:w:C:\Users\Taler\AppData\Local\Temp\arduino_build_371376/Blink.ino.hex:i avrdude: Version 6.3-20190619
System wide configuration file is "C:\Users\Taler\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf"
         Using Port                    : COM20
         Using Programmer              : arduino
         Overriding Baud Rate          : 57600
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x0c
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x8c
...
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x6
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x73
avrdude done.  Thank you
An error occurred while uploading the sketch

Hi @protovtol. Select Tools > Processor > ATmega2560 (Mega 2560) from the Arduino IDE menus and then try uploading to your Mega boards again.

There have been two variants of the Mega board, each with a different microcontroller. The Tools > Processor menu allows you to select between the two, so it is essential to have the right setting there in order for the upload to succeed. I can see that you had "ATmega1280" selected from the menu, but you must have the other variant of the board with the ATmega2560 microcontroller.

1 Like

OMG it worked! And I scoured the whole globe for a solution! I had noticed the"Processor" menu choice in the past, but couldn't figure out why would anyone select the 1280, so that it must default to 2560 processor. But no, it sticks to 1280 when changing boards, and when the board is changed back to 2560, processor remains 1280.

I did not consciously set it to 1280. Must have accidentally changed processors, without realizing it was set to 1280. I even noticed this in the avrdude command string (-patmega1280) and changed it to -patmega2560. But it did not connect for some reason. I had no idea this was a user menu choice.

Thank you so much in0. That saved me a lot of grief. I was forced to IDE 2.0 because of this, and guess what, I like it more.

Thanks again.

You are welcome. I'm glad it is working now.
Enjoy!

1 Like

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