# Troubleshooting an ATMega328p clock setting

I am trying to run my ATMega at 16MHz using this crystal

I set the lfuse bit to F7 (see here)

The command I used to set the lfuse bit was

C:\>avrdude -p m328p -P lpt1 -c stk200 -U lfuse:w:0xf7:m

avrdude: AVR device initialized and ready to accept instructions

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

avrdude: Device signature = 0x1e950f
avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xf7:
avrdude: load data lfuse data from input file 0xf7:
avrdude: input file 0xf7 contains 1 bytes

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

avrdude: verifying ...
avrdude: 1 bytes of lfuse verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.


I had code on the chip that was blinking a LED once every second. After I set the lfuse bit it stopped.

I tried to read the lfuse bit via

C:\Documents and Settings\admin>avrdude -p m328p -P lpt1 -c stk200 -U lfuse:r:-:
h -U hfuse:r:-:h

avrdude: AVR device not responding
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.

avrdude done.  Thank you.


I believe I have the crystal setup correctly on pins 9 (TOSC1) & 10 (TOSC2). I am using 22 pF caps.

I am seeing 5V on pin 10 and 0V on pin 9

What steps can I take to troubleshoot this?

-

That's a really odd response you're seeing. Of course there's the obvious suggestion of: have you tried power cycling everything in the chain? (PC->STK200->devboard) But also, do you have another AVR programmer you can try? Do you have another ATmega328P you can try reading & writing? Have you ever been able to read fuse settings with any programmer?

Other things to try: Can you remove the crystal and see if you can communicate with the chip then? Does your programmer have the ability to adjust SCK speed? (the STK500 can do this, not sure about STK200) It may be the chip got in a really low speed mode.

As a last resort, you'll need to put the chip in a high-voltage programmer. I know at least the STK500 can do that, and there are a few circuits out there for hacking a HVP out of an Arduino or LPT port. I've had to resuscitate a few AVR chips that way because of an electrical glitch or I flubbed settings.

-

A couple thoughts. What were the fuses set to before you changed them? have you confirmed your wiring with the schematic? Remember, it needs the crystal connected to program it.

Checking the datasheet, it looks like 0xF7 was the wrong setting to use. CKSEL 3..0 is set to 1000 by 0xF7. There is a table in the datasheet, which recommends this value for oscillators from .8 to .9MHz, and specificially states that this setting is not to be used with crystals. The correct setting for the low byte of the fuses was 0xF1, this puts CKSEL 3..1 at 111, which is recommended for 16MHz quartz crystal. The relevant info is on page 29 of the datasheet.

You'll probably need an old-school programmer to fix the issue, otherwise you've bricked the chip.

-