Electronic – Failing to write ATMega16U4 fuses with avrdude

avravrdudeisp

I'm trying to set the fuses on an ATMega16U4 with avrdude. The first problem I encountered is that avrdude version 5.11.1 does not seem to support ATMega16U4. Someone mentioned on avrfreaks that you should just copy the ATMega32U4 block on avrdude.conf and change the signature, description and memory sizes to fit the ATMega16U4 and thats what I did, here is my avrdude.conf: http://paste.dy.fi/SQP

This seems to work but I'm not 100% convinced.

The actual problem is that avrdude is unable to set the fuses (I'm using my buspirate as the ISP programmer):

avrdude -c buspirate -p m16u4 -P /dev/ttyUSB0 -U lfuse:w:0xe2:m -U > hfuse:w:0xd8:m -U efuse:w:0xf8:m

Detecting BusPirate…
**
** Bus Pirate v3a
** Firmware v5.10 (r559) Bootloader v4.4
** DEVID:0x0447 REVID:0x3046 (24FJ64GA002 B8)
** http://dangerousprototypes.com
**
BusPirate: using BINARY mode
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e9488
avrdude: reading input file "0xe2"
avrdude: writing lfuse (1 bytes):

Writing | | 0% 0.00s >***failed;
Writing | ################################################## | 100% 0.07s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xe2:
avrdude: load data lfuse data from input file 0xe2:
avrdude: input file 0xe2 contains 1 bytes
avrdude: reading on-chip lfuse data:

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

avrdude: verifying …
avrdude: verification error, first mismatch at byte 0x0000
0xe2 != 0x5e
avrdude: verification error; content mismatch

avrdude: safemode: lfuse changed! Was e2, and is now 5e
Would you like this fuse to be changed back? [y/n] y

It seems to be able to read the microcontroller just fine, reads the correct signature and reads the correct (default) fuses but fails to change them.

Here is a more detailed avrdude printout with -vvv: http://paste.dy.fi/JA6

I'm using a 12MHz crystal with 22p ceramics and I have a 4.7kohm pull-up resistor on the reset.

Does anybody have any idea why it is not working? I've gone through the connections with a multimeter etc. several times and they are all ok. I also doubt that reading the device would even work if the connections had a problem. The ATMega is brand new, never used, never programmed (so the lock fuses are not set) etc.

Best Answer

SOLVED IT! For some reason the AVR ships with the lock bits enabled!? According to the datasheet this is how it is specified. Erasing the chip disables the lock bits and enabled me to program the fuses.