Cannot enter programming mode on ATmega16U2

Go To Last Post
25 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I broke the ATmega16U2 on my Arduino Mega 2560 R3 board. I thought I would just order a new one, and program it with my Jtagice3. After soldering the new chip in, it wouldn't enter programming mode, but I thought it could be a few things I did wrong--soldering a QFN32 package is not that easy... I unsoldered and soldered it a few more times, but nothing changed. Of course at this point I may have already fried it by my heatgun. :-/

 

Luckily, I ordered two chips, so I figured l would try the other one in a jig. I connected SCK, MISO, MOSI, and RESET, and provided power on pins 3 (GND) and 4 (VCC). Still couldn't enter programming mode. This is the error message I got when using atprogarm.

 

C:\Users\gal\Documents>atprogram -t jtagice3 -i isp -d atmega16u2 info
Firmware check OK
[ERROR] Could not establish connection to device. Please check input parameters, hardware connections, security bit, target power, and clock values.
Failed to enter programming mode. ispEnterProgMode: Error status received: Got 0xc0, expected 0x00 (Command has failed to execute on the tool). (TCF Error code: 1)

 

The same jig worked for other ATmega chips, so I am not sure what I did wrong. Just to make sure, I connected RESET to VCC with a 10k, and provided VCC to AVCC, too. Nothing changed. This is how the jig looks like now. The dot on the other side of the chip marking pin #1 is at the lower right corner, I checked.

 

 

 

So, my question if someone can spot something I'm doing fundamentally wrong.

 

Thanks in advance for any advice,

Miki.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you own any capacitors?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, I do.

 

If it's the the lack of decoupling 100n capacitor on the power you want to bring up, maybe I underestimate the importance of the decoupling capacitors, but just to program an ATmega (in a jig) I never had any problem being sloppy and skip it.

 

But just to be on the safe side, I added one, but it behaves the same way.

 

 

If it's somewhere else you wanted to suggest me to add a capacitor (or more), please let me know, even if I don't have a certain value, I'm sure I can order them. But I have plenty...

 

Thanks,

Miki.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What about the ISP frequency? It should be 250KHz or better 125KHz.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I suppose the clock frequency was the default 125kHz, but I tried a few, even lower values. Still no luck.

 

C:\Users\gal\Documents>atprogram -t jtagice3 -i isp -d atmega16u2 -cl 125khz info
Firmware check OK
[ERROR] Could not establish connection to device. Please check input parameters, hardware connections, security bit, target power, and clock values.
Failed to enter programming mode. ispEnterProgMode: Error status received: Got 0xc0, expected 0x00 (Command has failed to execute on the tool). (TCF Error code: 1)

C:\Users\gal\Documents>atprogram -t jtagice3 -i isp -d atmega16u2 -cl 75khz info
Firmware check OK
[ERROR] Could not establish connection to device. Please check input parameters, hardware connections, security bit, target power, and clock values.
Failed to enter programming mode. ispEnterProgMode: Error status received: Got 0xc0, expected 0x00 (Command has failed to execute on the tool). (TCF Error code: 1)

C:\Users\gal\Documents>atprogram -t jtagice3 -i isp -d atmega16u2 -cl 10khz info
Firmware check OK
[ERROR] Could not establish connection to device. Please check input parameters, hardware connections, security bit, target power, and clock values.
Failed to enter programming mode. ispEnterProgMode: Error status received: Got 0xc0, expected 0x00 (Command has failed to execute on the tool). (TCF Error code: 1)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

Where are your crystal and caps?  The m8/16/32u2 come fused for an external crystal.:

 

 

By the way, I love your lumber jig! :-)

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Mon. May 25, 2020 - 05:42 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The m8/16/32u2 come fused for an external crystal.:

 

That's not what the datasheet says unless I have a buggy datasheet.

 

8.3.1 Default Clock Source
The device is shipped with internal RC oscillator at 8.0 MHz and with the fuse CKDIV8 programmed, resulting in 1.0 MHz system clock. The startup time is set to maximum and time-out
period enabled. (CKSEL = "0010", SUT = "10", CKDIV8 = "0"). The default setting ensures that
all users can make their desired clock source setting using any available programming interface.
 

 

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I would doubt if this circuit would work or enter programming mode. The wires are relatively long, noise would be an issue here. add a 4,7 uF in addition to your 100nF. 100nF should be as close as possible to the pin...

 

If you have an osci, take a look at the signals in the programming pins. also small issue here, I would suppose the programmer does not provide voltage to run the chip so you have to power up your circuit externally 5,5V - 3.3V would be sufficient...but take care not to damage it.

 

Regards,

Moe

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

joeymorin wrote:

 

Where are your crystal and caps?  The m8/16/32u2 come fused for an external crystal.:

 

 

Hmmm--from the datasheet I linked to from Mouser

 

 

7799E  09/12

 

 

And OP is saying 125kHz.

 

[I haven't worked with this model series, but] I seem to recall FLIP being used on these chips.  Does that setup also preclude ISP?  This Arduino article mentions ICSP.

 

...

When you first purchase a legitimate ATMEL ATMEGA16U2 chip, it is actually loaded with a default DFU firmware. If you did not purchase the microcontroller from the legitimate source, there might not be any firmware pre-loaded inside. In this case, you can only load the bootloader firmware using the ATMEL ICSP programmer method.

If you built the basic USB circuit using the ATMEL microcontroller and plugged it into your computer’s Windows Operating System (example Win7), you should be able to see a USB device name “ATmega16U2” under a folder libusb-win32 devices in the Win7 Device Manager.

...

Using the ATMEL FLIP software, you will be able to load firmware or bootloader using its default ATMEL DFU bootloader. ..

https://www.arduino.cc/en/Hackin...

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Mon. May 25, 2020 - 12:24 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

js wrote:

That's not what the datasheet says unless I have a buggy datasheet.

theusch wrote:

Hmmm--from the datasheet I linked to from Mouser

theusch wrote:

7799E  09/12

Curious.

 

The datasheets I have on my machine are from the last Atmel Techlib DVD, filenames m8U2_16U2_32U2_D1110.pdf and m8U2_16U2_32U2_E0912.pdf.  The versions are 7799D-AVR-11/10 and 7799E-AVR-09/2012, respectively.  However, note that in the latter, the page footer reverts to showing 7799D-AVR-11/10 starting on page 7 (Section 6, AVR CPU core), right up until page 298, switching back to 7799E-AVR-09/2012 on page 299 (Sections 32, Errata).

 

This doesn't appear to be a grievous error:

 

 

Also, I'm not sure what Lee and John are on about.  The datasheet I just retrieved from Mouser, and the one I just retrieved straight from Microchip, are the same as my m8U2_16U2_32U2_E0912.pdf (7799E-AVR-09/2012).  All clearly show the default is an external crystal.

 

 

EDIT:  Fixed broken character encoding in document names

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Mon. May 25, 2020 - 04:57 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

Ah.  I see.  The text you mention is on page 29, part of Section 8, System Clock and Clock Options.

 

The part I quoted from is from Section 25.2, Fuse Bits.  Furthermore, the default fuse bits shown are indeed for an external crystal.

 

 

 

 

 

How many USB parts which ship with a DFU bootloader also ship fused for internal RC?  Not zero, but not many.  And not this one, I think.  There is an error in the datasheet, but it is in section 8, not section 25.

 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK, so it seems you guys found me the fundamental problem. Correct me if I'm wrong, but it seems the consensus is that the error in the data sheet is in the text, and we have to trust the part where the fuse bits default values indicate the clock source fuses are programmed to 1110 (CKSEL3..0), and 01 (SUT1..0), which is Ceramic resonator, BOD enabled, startup 1K CK, additional delay 14CK, and frequency range 8-16 MHz.

 

I apologize for my ignorance, but is there a big enough difference between crystal and ceramic resonators, so that the Arduino Mega 2560 R3 board that comes with a crystal on it would not allow ISP because of lack of clock source?

 

But I'm also contemplating, wouldn't FLIP need a correct clock source, too? In other words, I'm doomed, unless I extend my jig and add a ceramic resonator. Although, according to the data sheet:

 

"These options are intended for use with ceramic resonators and will ensure frequency stability
at start-up. They can also be used with crystals when not operating close to the maximum frequency
of the device, and if frequency stability at start-up is not important for the application."

 

I'm sure startup frequency stability would not be a problem for programming, but the crystal is indeed at the maximum (16MHz).

 

Anyways, this is how the ATmega16U2 is fused in a working Arduino Mega 2560 R3.

C:\Users\gal\Documents>atprogram -t jtagice3 -i isp -d atmega16u2 -cl 125khz info
Firmware check OK
Tool jtagice3 has firmware version: 03.36
Target voltage: 4.95 V

Device information:

Name:       atmega16u2
JtagId:     N/A
Revision:   A
CPU arch.:  AVR8
Signature:  0x1e9489

Memory Information:

Address Space    StartAddress            Size

prog                      0x0          0x4000
  FLASH                   0x0          0x4000
  BOOT_SECTION_1       0x3e00           0x200
  BOOT_SECTION_2       0x3c00           0x400
  BOOT_SECTION_3       0x3800           0x800
  BOOT_SECTION_4       0x3000          0x1000

signatures                0x0             0x3

fuses                     0x0             0x3

lockbits                  0x0             0x1

data                      0x0           0x300
  REGISTERS               0x0            0x20
  MAPPED_IO              0x20            0xe0
  IRAM                  0x100           0x200

eeprom                    0x0           0x200

io                        0x0            0x40

osccal                    0x0             0x1

OscCal:     0x5a

Fuses:
EXTENDED (0b11110100):
   HWBE          0x0
   BODLEVEL      0x4

HIGH (0b11011001):
   DWEN          0x1
   RSTDISBL      0x1
   SPIEN         0x0
   WDTON         0x1
   EESAVE        0x1
   BOOTSZ        0x0
   BOOTRST       0x1

LOW (0b11111111):
   CKDIV8        0x1
   CKOUT         0x1
   SUT_CKSEL     0x3f

LOCKBIT (0b11111111 <-> 0xff):
   BLB1          0x3
   BLB0          0x3
   LB            0x3

 

Last Edited: Mon. May 25, 2020 - 03:12 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The difference between ceramic and quartz resonators is Q, which is typically higher for quartz, so they will take longer to stabilise.  This is reflected in the recommended start up time, 258CK + 14CK + 4.1 65 ms for the defaults, 16,000CK + 14CK + 65 ms for the Arduino Mega 2560 R3.

 

It's hard to say whether the default fuses would pose a problem for your first use case (soldered to the Mega, using its quartz crystal and caps).  I agree its unlikely, and that some other problem (solder bridge) cause your troubles first time round. 

 

For programming, you could also simply inject a clock signal into XTAL1.  If you inject, say, a 1 MHz clock, note that the system clock will be 1/8th of that (since the default is CKDIV8 programmed), or 125 kHz.  ISP clock needs to be < 1/4 of system clock, so make sure your ISP clock is < 31.25 kHz.

 

EDIT:  typo

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Mon. May 25, 2020 - 10:30 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


I added a 10MHz crystal and capacitors to the jig, don't laugh... ;-)

 

 

 And now I can communicate with the chip! :-)

C:\Users\gal\Documents>atprogram -t jtagice3 -i isp -d atmega16u2 -cl 125khz info
Firmware check OK
Tool jtagice3 has firmware version: 03.36
Target voltage: 4.95 V

Device information:

Name:       atmega16u2
JtagId:     N/A
Revision:   A
CPU arch.:  AVR8
Signature:  0x1e9489

Memory Information:

Address Space    StartAddress            Size

prog                      0x0          0x4000
  FLASH                   0x0          0x4000
  BOOT_SECTION_1       0x3e00           0x200
  BOOT_SECTION_2       0x3c00           0x400
  BOOT_SECTION_3       0x3800           0x800
  BOOT_SECTION_4       0x3000          0x1000

signatures                0x0             0x3

fuses                     0x0             0x3

lockbits                  0x0             0x1

data                      0x0           0x300
  REGISTERS               0x0            0x20
  MAPPED_IO              0x20            0xe0
  IRAM                  0x100           0x200

eeprom                    0x0           0x200

io                        0x0            0x40

osccal                    0x0             0x1

OscCal:     0x4c

Fuses:
EXTENDED (0b11110100):
   HWBE          0x0
   BODLEVEL      0x4

HIGH (0b11011001):
   DWEN          0x1
   RSTDISBL      0x1
   SPIEN         0x0
   WDTON         0x1
   EESAVE        0x1
   BOOTSZ        0x0
   BOOTRST       0x1

LOW (0b01011110):
   CKDIV8        0x0
   CKOUT         0x1
   SUT_CKSEL     0x1e

LOCKBIT (0b11101100 <-> 0xec):
   BLB1          0x2
   BLB0          0x3
   LB            0x0

 

However, I couldn't program it, because of the lock bits. Of course, a quick chip erase eliminated this "problem", and I could successfully program the "Arduino-COMBINED-dfu-usbserial-atmega16u2-Mega2560-Rev3.hex" firmware.

 

 

In conclusion, there is that misleading part in section 8 in the data sheet suggesting the chip comes with the fuses programmed for internal RC oscillator, while it doesn't, as correctly described in section 25.2. Also, it seems it came pre-programmed with the FLIP firmware, and the lock bits were set.

 

Thank y'all for all your advice!

 

Regards,

Miki.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

miklos.gal@gmail.com wrote:

I added a 10MHz crystal and capacitors to the jig, don't laugh... ;-)

It's beautiful!  ;-)

 

 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry guys, I still can't see where the datasheet shows the default fuse value as being set for external crystal blushsurprise

 

Only table 25.5 point 2 says

2. The default setting of CKSEL3..0 results in External crystal Oscillator 8MHz. See Table 8-1 on
page 29
for details.

but the table pointed to says that the default value for the fuses it (CKSEL = "0010", SUT = "10", CKDIV8 = "0") or internal oscillator with CKDIV8 programmed, or 1MHz.

 

Now for the diplomatic part: Could it be that the bare silicon comes programmed with the above and then a bootloader gets programmed into the chip to facilitate USB programming that needs the 12MHz clock? Therefore the fuse get changed to external crystal oscillator? phewww
 

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:
Sorry guys, I still can't see where the datasheet shows the default fuse value as being set for external crystal blushsurprise
Someone thoughtfully included screenshots in #11.

 

Default SUT[1:0] and CKSEL[3:0] values are 0b01 and 0b1110, which is clearly for the low-power crystal oscillator 8-16 MHz, for ceramic resonator and slowly rising power.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:

but the table pointed to says that the default value for the fuses it (CKSEL = "0010", SUT = "10", CKDIV8 = "0") or internal oscillator with CKDIV8 programmed, or 1MHz.

>>That<< table is wrong.  The table of the fuse bytes/bits themselves in 25.2 is the correct one.

 

Just another copy/paste error, which Atmel are famous for.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


 

 

Are you referring to the default 0x5E value for the low fuse in table 25.5? Because even that would be problematic as it clearly shows the CKDIV8 bit programmed reducing, say, a 12MHz clock to 1.5MHz. smiley The programming simulator does not support this chip but with a JTAG I can set the low fuse to that value even if I can't program.

 

 

updated screen shot with all 3 default fuse settings.

 

 

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Last Edited: Tue. May 26, 2020 - 01:07 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Updated screen shot above and downloaded new datasheet.

 

Is it possible for miklos.gal to post what the actual fuses are set at now?

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:
Because even that would be problematic as it clearly shows the CKDIV8 bit programmed reducing, say, a 12MHz clock to 1.5MHz. smiley
Why would that be problematic?  I've not worked much with the 16u2, but isn't the USB clock separate from the system clock?  In any event, I expect that DFU tickles CLKPR as it pleases anyway.

 

 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


js wrote:

Is it possible for miklos.gal to post what the actual fuses are set at now?

 

I had already re-programmed the fuses to the Arduino board requirements, and it looks like this:

 

 

So I cannot take a screen shot of how the fuses looked from the factory, but in post #14 I have the output of "atprogram info", which shows the fuses as they were before any programming.

 

Fuses:
EXTENDED (0b11110100):
   HWBE          0x0
   BODLEVEL      0x4

HIGH (0b11011001):
   DWEN          0x1
   RSTDISBL      0x1
   SPIEN         0x0
   WDTON         0x1
   EESAVE        0x1
   BOOTSZ        0x0
   BOOTRST       0x1

LOW (0b01011110):
   CKDIV8        0x0
   CKOUT         0x1
   SUT_CKSEL     0x1e

LOCKBIT (0b11101100 <-> 0xec):
   BLB1          0x2
   BLB0          0x3
   LB            0x0

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just a quick update. I finally successfully soldered the QFN32 package in, and the Arduino board is fully functional. :-)

 

I have to tell you it was a nightmare, though. I still had to solder and desolder it a few times, there was always some lack of connection underneath (I'm quite sure there were no bridges, those are easy to check with a multimeter). Sometimes a little pressure on top of the chip made the connection. ;-) But boy, these chips are resilient! They survived so much heat from my heat gun. Surprisingly, the first chip I though I had fried is the winner, but I definitely burnt the other one (doesn't work in the jig anymore).

 

Clearly, boards with QFN packages are not designed to be serviced. And I'm sure it would have even been a lot cheaper to get another board for $15, considering I've been fighting with it for about two weeks. But where's the fun in that!? :P

 

Thanks again,

Miki.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Well they are designed to be serviced IF you have the correct tools. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have the same problem. What I understood is that you changed the crystal to go into programming mode. Is this true? If this is true, how the manufacturer of these boards do the same process: programming the bootloader??? In short, I am having the same problem. If the solution is this complex, this is crazy!