Arduino Mega after Bootloading w/ UNO as programmer: led 13 blinks undefinitely

Hi there

Have 3 Arduinos One UNO Rev 3 (works perfectly) and two MEGA 2560 (w/ different problems, see below).
Will call it Ren and Stimpy, because after all these process we are friends and they dont deserve to be called A and B. So,

  • UNO have chips MEGA16U2 and ATMEGA 328P.
  • Ren and Stimpy have chips MEGA16U2 and ATMEGA2560. Im not sure what happened to it. A friend brought them to me without knowing details (yes, I would like to know its past too).

REN

Ren was recognized by my PC (leds yellow and green ok). COM is shown in PC when I connect the board. The controller its ok. But couldnt upload any code. I saw that leds TX and RX was not working. Not sure if it was a problem caused by ATMEGA16U2 or if the problem its the ATMEGA2560.

  • Tried to access to DFU mode jumping Reset and GND on ICSP near the USB port. Couldnt do it. So the solution I know via DFU ---> FLIP w/ reinstalling hex file of MEGA16U2 was not able :confused:

  • Tried w/ Loopback test as marked by "Coding Bafly" (Loop-Back Test Instructions - Installation & Troubleshooting - Arduino Forum). No echoes received in Serial Monitor.

  • Tried to bootupload Ren using the UNO as programmer, following this steps:

  • Connected UNO to PC (port and board also selected).

  • Opened ArduinoISP from Examples and uncommented the line for using old Uno style wiring// (using pin 11, 12 and 13 instead of the SPI header). I think this step was not neccesary.Uploaded ArduinoISP from Examples (no other boards or wirings connected to UNO)

  • Disconnectesd UNO and proceeded w/ wiring (Pin 13 on UNO ---> 52 on Ren, Pin 12 on UNO ---> 50 on Ren // Pin 11 on UNO ---> 51 on Ren // Pin 10 on UNO ---> Reset on Ren (the one located on Power Side) // +5V on UNO ---> +5V on Ren (the one located on Power Side) // GND on UNO ---> GND on Ren (the one located on Power Side).

  • Connected leds circuit over pins 7, 8 & 9 as marked here: https://www.arduino.cc/en/Tutorial/ArduinoISP.

  • Connected UNO via USB to PC.... Port: the same it was. Board is changed for the target (Ren)

  • Burn Bootloader.

  • Process completed ok, no warnings in red. But.....

Connected Ren to PC. COM is recognized well, the same as before. But still cant upload codes. When try to upload "Blink" sketch the message is:

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer
Rx and TX leds are not blinking. There is only one difference: led on 13 blinks (lapse of 0.5 secs) all the time. If I press Reset button, this yellow led keeps on, but restart to blink when I release it. What does it mean? Do you think that Ren is leading w/ a MEGA16U2 problem? If so, Could I upgrade it in a different way than the DFU ---> FLIP process? If so, dont know how to do it, specialy if I have to deal with avrdude commands...

STIMPY

With Stimpy, the situation it was a bit worse. Stimpy was not recognized by PC, then port couldnt be selected for uploading codes via USB. I've followed the same procedure like with Ren....

After that, PC still doesnt recognize the board and again port is not able on IDE. In the same way that with Ren, now led on 13 blinks (lapse of 0.5 secs).

What could be wrong w/ them?
Many thanks in advance. From Ren, from Stimpy and of course, from me!
Cheers!

Updating :slight_smile:

Tried to access DFU mode by the procedure for ATMEGA16U2 because the one I was trying was prepared for ATMEGA8U2. The procedure is marked here: Fixing Linux firmware issues on Arduino Mega 2560 | Wayne and Layne... not seen in any official Arduino reference

No good results. Cant access to DFU mode anyway.

In Use Arduino Mega 2560 as ISP to bootload Arduino Mega 2560 - Microcontrollers - Arduino Forum, user REM14 was stacked on a similar problem. No access via USB and requiring upgrade the ATMEGA16U2 firmware. The solution other users gave him was using other Arduino as programmer (Arduino MEGA of a good board in that case) and its bad board, w/ wiring connected in the following way: connecting the ICSP pins of the ATMEGA2560 (good board) to the ISCP2 pins of its second chip near the USB port. Wires according this picture:

In my case, the good board is an Arduino UNO.

Im not very comfortable with typing commands in cmd over avrdude, so I've decided to go for the Nick Gammon programmer. According to https://www.gammon.com.au/forum/?id=11635&reply=2#reply2, the bootloader for ATMEGA16U2 is supported. Then I guessed that I could installing that firmware w/ the wiring configuration I showed above (in my case the programmer is the UNO but I also use the ICSP for programming).

I've downloaded from Github the ATmega_Board_Programmer

(If you are as newbie as me you will ask how to load a complete folder from github, just because in adittion to the .ino file you'll need the other ones pointed in that folder: go to DownGit. Then you have to paste the following link arduino_sketches/Atmega_Board_Programmer at master · nickgammon/arduino_sketches · GitHub)

Then:

  • Connected UNO to PC (port and board also selected). No wiring yet, just USB port.
  • Opened Atmega_Board_Programmer sketch and uploaded.
  • Disconnectesd UNO and proceeded w/ wiring as showed.
  • Connected UNO via USB to PC.... Port: the same it was. Board is changed for the target (Ren).
  • Selected "Arduino as ISP" as programmer.
  • Opened Serial Monitor and changed bauds to 115200. Now I see the code running (before doing that I had just symbols). The output is
16:24:33.561 -> 
16:24:33.561 -> Atmega chip programmer.
16:24:33.561 -> Written by Nick Gammon.
16:24:33.561 -> Version 1.38
16:24:33.561 -> Compiled on Aug 20 2020 at 13:24:50 with Arduino IDE 10813.
16:24:33.561 -> Attempting to enter ICSP programming mode ......................................................
16:24:39.961 -> Failed to enter programming mode. Double-check wiring!
16:24:39.961 -> Type 'C' when ready to continue with another chip ...

Failed to enter ICSP. Double check wiring...
So please, could you have any hint about how upgrade ATMEGA16U2?
Many thanks!

This works. Takes a little reading to setup for both Uno and Mega.

Many thanks for your help kprims. I'll check it carefully and tells you how it goes :slight_smile:

Hi again.

Almost have the customized file boards.txt required, but cant finish it withou a brief (?) question about fuses.

I understand that for creating the custom board for restoring ATMEGA 16U2 for UNO, Dmjlambert got information available for the UNO board in the original file "boards.txt" and made some required corrections.

I'm not sure about definition of values for low, high and extended fuses for creating these custom boards. Do I have to keep the one shown for the "main" chip of that board? :roll_eyes: I mean..

  • If I want to create the custom board for the ATMEGA 16U2 for an Arduino UNO, should I keep the fuses values shown on boards.txt for the ATMEGA 328 section?
  • Do I have to proceed in the same way for creating the custom board for the ATMEGA 16U2 for an Arduino MEGA, considering those fuses values shown on boards.txt for the ATMEGA 2560 section?

Many thanks! :slight_smile:

PD: Found this "very simple" way to define those fuses... AVR® Fuse Calculator – The Engbedded Blog. Please, dont tell me that I should complete that cells :astonished:

The fuses are set for the atmega16u2 chip. They are the same for both the Uno and the Mega.

My custom boards.txt

unorestore.name=UNO 16U2 Restore Firmware
unorestore.bootloader.tool=arduino:avrdude
unorestore.bootloader.low_fuses=0xff
unorestore.bootloader.high_fuses=0xd9
unorestore.bootloader.extended_fuses=0xf4
unorestore.bootloader.file=Arduino-COMBINED-dfu-usbserial-atmega16u2-Uno-Rev3.hex
unorestore.bootloader.unlock_bits=0x3F
unorestore.bootloader.lock_bits=0x0F
unorestore.build.mcu=atmega16u2
unorestore.build.f_cpu=16000000L
unorestore.build.board=uno.build.board=AVR_UNO
unorestore.build.core=arduino:arduino
unorestore.build.variant=standard


MEGArestore.name=MEGA 16U2 Restore Firmware
MEGArestore.bootloader.tool=arduino:avrdude
MEGArestore.bootloader.low_fuses=0xff
MEGArestore.bootloader.high_fuses=0xd9
MEGArestore.bootloader.extended_fuses=0xf4
MEGArestore.bootloader.file=Arduino-COMBINED-dfu-usbserial-atmega16u2-Mega2560-Rev3.hex
MEGArestore.bootloader.unlock_bits=0x3F
MEGArestore.bootloader.lock_bits=0x0F
MEGArestore.build.mcu=atmega16u2
MEGArestore.build.f_cpu=16000000L
MEGArestore.build.board=uno.build.board=AVR_Mega2560
MEGArestore.build.core=arduino:arduino
MEGArestore.build.variant=standard

Below the Burning Bootloader Output. Got the famous "Yikes!...."
The same message for both MEGAs boards. Tried several times pressing "Burn Bootloader" just in case.
Should I try putting as programmer another MEGA (good board) instead of UNO?

Thanks a lot!

Arduino:1.8.13 (Windows 7), Tarjeta:"ATMEGA 16U2 Restore Firmware"
C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega16u2 -cstk500v1 -PCOM11 -b19200 -e -Ulock:w:0x3F:m -Uefuse:w:0xF4:m -Uhfuse:w:0xD9: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                    : COM11
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
         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
           flash         65     6   128    0 yes     16384  128    128  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 = 0xffffff (probably .avr8x_mega) (retrying)
Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0xffffff (probably .avr8x_mega) (retrying)

Error quemando bootloader
Reading | ################################################## | 100% 0.02s
avrdude: Device signature = 0xffffff (probably .avr8x_mega)
avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override this check.
avrdude done.  Thank you.

Uno should be good.

avrdude: AVR device initialized and ready to accept instructions

Double check your wiring.

Chips may be bad

Wire are ok.
Just 6 wires and the capacitor, following the diagram posted before.
I guess ATMEGAs 16U2 are bad.

Even that, have learnt many things these days. And now have the board.txt prepared for refreshing firmwares for other ATMEGAS 16U2.

Many thanks again krpims,
Have a nice weekend

Well good luck. Hope you get to try it out on a good chip.

PD: something useful for someone trying the same procedure.
When saving your boards.txt customized, have to do it w/ ANSI code!
I've been 20 min exploring what was wrong inside the txt but the problem was there. STD coding appears like UTF-8

Cheers!