Fuse mystery with a Duemilanove/ATmega328P

I use my Duemilanove (w/ 328) for general hackery (using a Mac most of the time, but sometimes OpenBSD), so I've never troubled myself with understanding the fuses. Recently I've been messing about with some timing stuff, which led me in a circle through AVRlib and the ATmega data sheet, and a closer look at my current fuses settings.

Somehow my unit has 0x0, 0x0, 0x0 for the lfuse, hfuse and efuse settings. Which the alert reader will realize is pretty different from what boards.txt says it should have.

I have no idea how I did this, since I've never deliberately reset the fuses on this thing. But who knows? Like I said, I didn't really bother to think about this stuff until now.

Anyway, I'm wondering how I can set these back to the Arduino defaults (which include changes to the clock settings that I think I'd prefer.) When I use avrdude to try and unlock and set them, I get communication errors. I can otherwise flash the unit with new programs and so on. It is only when I try to set the fuses that I get these errors.

clvrmnky@thor:~/src/Demo/firmware $ make fuse
avrdude -C /usr/local/CrossPack-AVR/etc/avrdude.conf -p ATMEGA328P -c arduino -P /dev/cu.usb* -b 57600 -v -v -U lfuse:w:0xFF:m -U hfuse:w:0xDA:m -U efuse:w:0x05:m -U lock:w:0x3F:m

avrdude: Version 5.11.1, compiled on Feb 16 2012 at 22:11:20
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/usr/local/CrossPack-AVR/etc/avrdude.conf"
         User configuration file is "/Users/clvrmnky/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/cu.usbserial-A6008d3w
         Using Programmer              : arduino
         Overriding Baud Rate          : 57600
         AVR Part                      : ATMEGA328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         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       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 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 : Arduino
         Description     : Arduino
         Hardware Version: 2
         Firmware Version: 1.16
         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 = 0x1e950f
avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: reading input file "0xFF"
avrdude: writing lfuse (1 bytes):

Writing |                                                    | 0% 0.00s ***failed;  
Writing | ################################################## | 100% 0.13s

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

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

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
         0xff != 0x00
avrdude: verification error; content mismatch

avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: safemode: lfuse changed! Was ff, and is now 0
Would you like this fuse to be changed back? [y/n] 
avrdude: safemode: Fuses OK
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
make: *** [fuse] Error 1
clvrmnky@thor:~/src/Demo/firmware $ echo $?
2

It doesn't matter how I answer the question.

My Google-fu tells me that my bootloader is messed up somehow, and I have no problems using this as an opportunity to experiment with the Optiboot bootloader.

So, what is going on here? What am I missing? I'm using the CrossPack AVR tools from a makefile, if that isn't clear from the output above.

If you burn the bootloader with the Arduino program, it will also set the fuses.

Krodal:
If you burn the bootloader with the Arduino program, it will also set the fuses.

I've only begun to do my research, but it looks like you need a hardware programmer, or build a bit-banger with another ATmega device to do this.

For now, I'd like to figure out why I can't set the fuses. I can always go nuclear at some future point, of course. Maybe it's my excuse to buy another ATmega device, or Arduino.

I think the ArduinoISP does/may not read the fuses (and thus returns 0). If there were all 0 you (probably) wouldn't be able to program it.

I recently made a sketch that detects your current board and fuses:

If you have another board (which it looks like you do) you could load that sketch up, connect up the wires as shown on that page, and see what the fuses really are.

I can otherwise flash the unit with new programs and so on.

Flash this then:

#include <avr/boot.h>

#define SIGRD 5

void setup ()
{
Serial.begin (115200);
Serial.println ();

Serial.println ("Signature");

byte sig;
  sig = boot_signature_byte_get (0);
  Serial.println (sig, HEX);
  sig = boot_signature_byte_get (2);
  Serial.println (sig, HEX);
  sig = boot_signature_byte_get (4);
  Serial.println (sig, HEX);

Serial.println ("Fuses");
byte fuse;
  
  fuse = boot_lock_fuse_bits_get (GET_LOW_FUSE_BITS);
  Serial.println (fuse, HEX);
  fuse = boot_lock_fuse_bits_get (GET_HIGH_FUSE_BITS);
  Serial.println (fuse, HEX);
  fuse = boot_lock_fuse_bits_get (GET_EXTENDED_FUSE_BITS);
  Serial.println (fuse, HEX);
  fuse = boot_lock_fuse_bits_get (GET_LOCK_BITS);
  Serial.println (fuse, HEX);
}

void loop () {}

That self-detects the fuses and displays them.

Nice. I've been reading the AVRlib docs, and it should have occurred to me to write a reflexive sketch and listen on the serial port. Of course, I didn't know that avrdude could not return good values.

So, now that I know that avrdude can't actually read the fuses through a plain bootloader Arduino, everything makes a little more sense.

I get this:

Signature
1E
95
F
Fuses
FF
DA
FD
CF

Which means "nothing to see here, move along."

Thanks.

So did I, but to detect the Arduino's own fuse and signature: Arduino Playground - ShowInfo (use command 'i')

Krodal:

[quote author=Nick Gammon link=topic=104708.msg785538#msg785538 date=1336351670]I recently made a sketch that detects your current board and fuses

So did I, but to detect the Arduino's own fuse and signature: Arduino Playground - ShowInfo (use command 'i')
[/quote]

This is a nice bit of kit. Consider this swiped for my collection.