Mega board troubleshooting (timeout error)

I know this error is quite common, however non of suggested answers I found on this forum or anywhere on google actually worked. Although I managed to fix some issues, I am still not able to upload sketch through Arduino IDE. I am not able to tell what I did wrong, most probable is that I shorted something, when not cautious when manipulating around.

I am using Arduino Mega2560 board on Windows 10. In Arduino IDE I am getting right board info and also Arduino board appears in Port menu correctly as COM5(Arduino Mega or Mega 2560).

I am getting avrdude: stk500v2_ReceiveMessage(): timeout when trying to upload sketch, so I tried to change in boards.txt the upload.protocol to stk500v2, but it didn't work. Then I tried loop-back test, didn't work either. After few tries I suspected that the ATmega16U2 may be damaged.

Thus I bought new one (along with AVR ISP MKII ECO) and I managed to replace the ATmega16U2 MCU and upload new firmware (Arduino-usbserial-atmega16u2-Mega2560-Rev3.hex). I tried to read the flash back so firmware is on the mcu.

Now the loop-back test passed, also I successfully tested the mega mcu with blink sketch uploaded via the ICSP with MKII. However I am still getting timeout error in Arduino IDE.

I could have try new firmware first, instead replacing the mcu first, when I am thinking about it now, so my question is, if there is possibility that the ATmega16U2 is somehow incorrectly soldered to the board, or what else could be wrong? Next thing I noticed, is the TX LED is lid all the time now, but it lid only after some time, it wasn't right after uploading firmware or sketch, although the loop-back test still works. How can I troubleshoot the board?

niva_v_kopirce:
Now the loop-back test passed, also I successfully tested the mega mcu with blink sketch uploaded via the ICSP with MKII. However I am still getting timeout error in Arduino IDE.

For uploading via serial line the bootloader is necessary in ATmega2560. However, you erased the bootloader by uploading Mega via ISCP. Just upload the bootloader and it should work.

BTW: Niva v kopírce? :slight_smile:

Sorry my mistake I didn't mention this, but before I tried to upload blink sketch via ICSP, first thing I did was trying to "Burn bootloader" from IDE I got error

Error while burning bootloader. 
avrdude: usbdev_open(): did not find any USB device "usb" (0x03eb:0x2104)

Even when I had Mega selected in boards and Port.
So I thought I have to upload the bootloader via ICSP, so I also tried to upload bootloaders\stk500v2\stk500boot_v2_mega2560.hex into Mega board through AtmelStudio, it went OK, but I am still not able to upload sketch (timeout error) nor burn bootloader (again) via IDE.

Budvar10:
BTW: Niva v kopírce? :slight_smile:

Přihlášeno přes google účet, asi k němu mám tuhle přezdívku, moje oblíbené už byly zabrané, tak jsem musel vymyslet něco co nikdo ještě nemá.... :slight_smile:

EDIT: Ah, I found out I have to Burn bootloader using ICSP AND IDE... But there is few options I had to try. My AVR Programmer MKII ECO has 4 switches, first is for providing supply for target device and second switching between AtmelStudio / AVR Dude and Bascom. When I disconnect Arduino board from USB and provide supply voltage for arduino from MKII and burn bootloader I get error mentioned above. The same apply for switch in position for AVR Dude.

When I switch providing supply voltage for Arduino off, and the third switch to position for Atmel Studio then connect Arduino board to USB and then burn bootloader I got this messages:
AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude -C\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf -v -patmega2560 -cstk500v2 -Pusb -Uflash:w:C:\Program Files (x86)\Arduino\hardware\arduino\avr/bootloaders/stk500v2/stk500boot_v2_mega2560.hex:i -Ulock:w:0x0F: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 "AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf"
Using Port : usb
Using Programmer : stk500v2
avrdude: reading input file "0x3F"
avrdude: writing lock (1 bytes):

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

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.00s

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

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

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.00s

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

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

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.00s

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

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

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.00s

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

avrdude done. Thank you.

avrdude: usbdev_open(): Found AVRISP mkII, serno: 000200212345
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 : STK500V2
Description : Atmel STK500 Version 2.x firmware
Programmer Model: AVRISP mkII
Hardware Version: 0
Firmware Version Master : 1.24
Vtarget : 3.3 V
SCK period : 8.00 us

avrdude: AVR device initialized and ready to accept instructions

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

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: stk500v2_recv_mk2: error in USB receive
avrdude: usbdev_send(): wrote -5 out of 1 bytes, err = libusb0-dll:err [_usb_reap_async] reaping request failed, win error: A device attached to the system is not functioning.

avrdude: stk500_send_mk2(): failed to send command to serial port
avrdude: stk500v2_recv_mk2: error in USB receive
avrdude: usbdev_send(): wrote -116 out of 1 bytes, err = libusb0-dll:err [_usb_reap_async] timeout error

And the last paragraph just repeats itself endlessly.

Ok I fixed the bootloader issue, I was missing JUNGO driver for my MKII and I successfully uploaded bootloader.

Of course another problem came up. Now The arduino board does not response after connecting to PC via USB - PC won't do the "USB device connected" sound. It had disconnected (made the USB disconnected sound) when Arduino was powered by USB and connected to MKII for programming after few minutes.
I tried to reinstall firmware on ATmega16U2, but I think I messed up the soldering process, because it is acting strangely. Atmel Studio has problems to read mcu, and when it reads mcu, it won't upload firmware with timeout errors - either when programming or erasing...Its unstable, after some time it stops communicating with MKII.

Do not power Arduino form USB and MKII at the same time.

Of course I switched the supply voltage for target device on MKII off before connecting the USB. But PC does not register any device connected to PC when plugging in arduino board alone, but Mega runs its blinking program (probably uploaded along with bootloader?).

If PC cannot see Arduino the the problem is with USB/serial transceiver, i.e. 16U2. You mentioned you had to replace it so I am supposing it was damaged somehow. Did you check what else was hit by damage? I mean circuit around 16U2, USB and regulator, and of course new 16U2. Maybe it has gone again.

I have the same suspicion. That was the reason i actually posted, to know what can I troubleshoot around the 16U2, there are some capacitors, resistor networks etc, but just by eyeballing it I cannot see any damage, I also tried to re-flow solder. But I really don't know how to find other erroneous components, I think probability that something else is damaged is small.

I suppose regulator circuit is actually not that important, since I don't use external power supply, so I believe even if it would be damaged it would not affect actual serial communication. The 16U2 replacement was a bit messy, so I believe it was not clear soldering, so I might damage 16U2 again. I am considering if replacement is worth it, since I have MKII programmer now and 16U2 is actually not that cheap, and working with QFN32 is difficult.