I'm trying to program the fuses and install the bootloader on a ATMEGA16U2 using the command line with AVRDUDE and a usbtiny programmer. I have done this successfully on about 50 identical boards, but on the latest batch of 20, 3 boards return the rc=-1 message because the device code is 0. I have checked voltages and continuity to the 6 pin header and for the 16 MHz crystal oscillator. The odd thing is that the oscillator is also not working. Both pins are about 2 VDC. As I understand this chip, the crystal oscillator is not required for setting the fuses anyway, in which case I may have a bad 16U2. Or am I wrong, and the chip will not respond to AVRDUDE unless the oscillator is working? In the later case, I should replace the crystal.
The system clock has to be running for In-System Serial Programing to work. If the chip is set to use a crystal, you need a working crystal or resonator to do serial programing.
If the system clock is not running, you can supply your own clock on the appropriate MCU crystal input pin. The programmer clock frequency has to be set to less than 1/4 of the provided clock, but I've even used an audio oscillator as an MCU clock source to rescue a chip with incorrect fuse settings.
Gammon describes how to to provide a clock for ATmega328 in this tutorial, and it should work for the 16U2 as well https://www.gammon.com.au/breadboard
The 16U2s are new from Mouser so they have the factory default fuses. Since I cannot even talk to the parts, there is no way they could have gotten incorrect fuse settings. I took a working 16U2 and set the fuses to the factory defaults and checked to see that the oscillator was working. It was. So I either got a bad batch of 16U2's or a bad batch of crystals. I use the same crystals on the ATMEGA328s on the same boards and they all worked fine. So out of 40 oscillators, 4 don't work and they are all associated with the 16U2s. Statistically, it looks like I need to replace the 16U2s. Ugh.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.