Initial Programming of a new ATMega16u2 ICSP

Hi,
I'm trying to make some EtherMega's (combined Arduino Mega and Ethernet Shield) from the freetronics design, but I'm struggling to program the ATMega16u2 using the ICSP pins. The AtMega2560 went fine and seems to work, but I just can't seem to get the ATMega16u2 chip to do anything.

I'm running this:

c:\Program Files (x86)\Arduino\hardware\arduino\avr\firmwares\atmegaxxu2>"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude" -C"C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"  -cstk500v1 -p m16u2 -PCOM4 -b19200 -v -U flash:w:Arduino-COMBINED-dfu-usbserial-atmega16u2-Mega2560-Rev3.hex -U lfuse:w:0xFF:m -vvvvv -U hfuse:w:0xD9:m -U efuse:w:0xF4:m -U lock:w:0x0F:m

and basically getting back:

avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.

avrdude: Send: Q [51]   [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]

Is there anything special I need to do to program a "virgin" 16u2?

Any advice would be appreciated. I've tried several different chips with no luck.

Thanks
James

James,

Doesn't look like you are getting to it.
What do you use for a programmer? Is it an Arduino as ISP or a true STK?
Are you sure it's connected properly and the port is right?

You may want to verify the hardware side first, maybe do a simple avrdude check.

Try (in a command prompt box) to change directory to avrdude:
cd "C:\Program Files (x86)\Arduino\hardware\tools\avr\bin"
Then:
avrdude -C..\etc\avrdude.conf -cstk500v1 -pm16u2 -PCOM4 -b19200 -vvv

That is if the port is indeed COM4 and the programmer is right.

Hi,
Thanks for getting back to me.

I'm using the Arduino as an ISP, which I've verified as working by loading the bootloader on the ATMega2560.

I had though it was hardware at first, but I've been over it so many times and built four separate boards with the same result. Also, If I disconnect the MISO / MOSI pins from the programmer, I get a "Programmer not Responding" result, which makes me think it is talking to it to some extent?

I did wonder if the crystal was maybe disabled and needed some sort of hack to get it kick started?

I will try your suggestion below and report back.

Thanks again
James

Did you set any fuses to the m16u2?
This site is pretty cool and has the 16u2 listed.

If it's a virgin chip, it is probably to default fuses, so you may need to change them according to your environment and wishes.

I have been successful setting the programer to 'arduino' with avrdude.
So you could also try -carduino instead of -cstk500v1

Please make sure the crystal and etc are soldered. The factory virgin clock for 16u2 is 8Mhz / 8, 1Mhz. But I do came across factory virgins that can only talk to the programmer in 250Khz.

Since you are using avrdude, add

-B bitclock

to the command parameter.

-B bitclock

"Specify the bit clock period for the JTAG interface or the ISP clock (JTAG ICE only). The value is a floating-point number in microseconds. The default value of the JTAG ICE results in about 1 microsecond bit clock period, suitable for target MCUs running at 4 MHz clock and above. Unlike certain parameters in the STK500, the JTAG ICE resets all its parameters to default values when the programming software signs off from the ICE, so for MCUs running at lower clock speeds, this parameter must be specified on the command-line. It can also be set in the configuration file by using the ’default_bitclock’ keyword."

Keep increasing the value

-B 1
-B 2
-B 3

until it starts to program. Once you get access to the chip, reset the fuse to the required value based on boards.txt

Hope this helps.

Cheers
JP

Hi JP,
How high might I need to go with this?

I am getting different results each time I increase the bitclock value now:

c:\Program Files (x86)\Arduino\hardware\tools\avr\bin>avrdude.exe -C..\etc\avrdude.conf -cstk500v1 -pm16u2 -PCOM6 -b19200 -B1

avrdude.exe: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.06s

avrdude.exe: Device signature = 0x000000 (retrying)

Reading | ################################################## | 100% 0.05s

avrdude.exe: Device signature = 0x000000 (retrying)

Reading | ################################################## | 100% 0.06s

avrdude.exe: Device signature = 0x000000
avrdude.exe: Yikes!  Invalid device signature.
             Double check connections and try again, or use -F to override
             this check.


avrdude.exe done.  Thank you.
c:\Program Files (x86)\Arduino\hardware\tools\avr\bin>avrdude.exe -C..\etc\avrdude.conf -cstk500v1 -pm16u2 -PCOM6 -b19200 -B2

avrdude.exe: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.08s

avrdude.exe: Device signature = 0x000000 (retrying)

Reading | ################################################## | 100% 0.12s

avrdude.exe: Device signature = 0x0001ff
avrdude.exe: Expected signature for ATmega16U2 is 1E 94 89
             Double check chip, or use -F to override this check.

avrdude.exe done.  Thank you.
c:\Program Files (x86)\Arduino\hardware\tools\avr\bin>avrdude.exe -C..\etc\avrdude.conf -cstk500v1 -pm16u2 -PCOM6 -b19200 -B3

avrdude.exe: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.07s

avrdude.exe: Device signature = 0xffffff (retrying)

Reading | ################################################## | 100% 0.05s

avrdude.exe: Device signature = 0xffffff (retrying)

Reading | ################################################## | 100% 0.09s

avrdude.exe: Device signature = 0xfffe00
avrdude.exe: Expected signature for ATmega16U2 is 1E 94 89
             Double check chip, or use -F to override this check.

avrdude.exe done.  Thank you.
c:\Program Files (x86)\Arduino\hardware\tools\avr\bin>avrdude.exe -C..\etc\avrdude.conf -cstk500v1 -pm16u2 -PCOM6 -b19200 -B4

avrdude.exe: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.05s

avrdude.exe: Device signature = 0x000000 (retrying)

Reading | ################################################## | 100% 0.07s

avrdude.exe: Device signature = 0x000000 (retrying)

Reading | ################################################## | 100% 0.07s

avrdude.exe: Device signature = 0x000000
avrdude.exe: Yikes!  Invalid device signature.
             Double check connections and try again, or use -F to override
             this check.


avrdude.exe done.  Thank you.