[SOLVED] Set Low Fuse Bit, Now Can't Program over ISP

Hey all,

I'm using an ATMEGA328P in one of my projects and am having a slightly big issue. I have an 8MHz resonator attached to the XTALI/O pins of the AVR, the same resonator that's used in the Arduino Pro. I was using the AVR ISP MKII along with AVR Studio and read in the factory set fuse bits. Then I changed the low fuse bit to 0x05, thinking this would set the chip to use the resonator. Boy, was I wrong. AVR Studio then gave me the error that fuse programming failed, and now I can't really do anything with the chip (note, regular .hex flash programming was working fine beforehand)

I read various articles online and tried debugging with avrdude at a slow speed, and below is the output:

> avrdude -p m328p -c avrispmkii -P usb -B5 -F

avrdude: stk500v2_command(): command failed
avrdude: stk500v2_program_enable(): bad AVRISPmkII connection status: Unknown status 0x00
avrdude: initialization failed, rc=-1
avrdude: AVR device initialized and ready to accept instructions
avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
avrdude: Expected signature for ATMEGA328P is 1E 95 0F

avrdude done.  Thank you.

I read that high voltage programming would fix this up, but the ATMEGA328P is soldered professionally on the board in the QFN package, so unsoldering is not really an option. And it was pretty expensive to have the board manufactured and assembled. Also, when I designed the board, I only added an ISP header.

Is there a way I can recover this chip while it's in-circuit?

I greatly appreciate any help.

Thanks a lot,
Aakash

Clock output on PORTB0; [CKOUT=0]

...is now enabled. What is connected to B0?

If by B0 you mean PB0 (ICP), there is nothing connected to it except a male header pin. Should I do something with this pin?

Thanks!

Programming the low fuse byte should not prevent you from programming via ICSP. Did you program the high fuse byte as well? If not, then most likely your resonator is not oscillating. You appear to have programmed the CKSEL bytes for a crystal or resonator in the frequency range 0.9 to 3.0 MHz (CKSEL 3..0 = 1010), whereas you are using a 8MHz resonator.

If you have an oscilloscope, then you can check whether you have a clock signal on the CKOUT pin. If there is no signal, then I suggest you disconnect the resonator and feed a clock signal to the XTAL1 pin. That should allow you to reprogram the fuse bytes.

Aakash:
If by B0 you mean PB0 (ICP), there is nothing connected to it except a male header pin. Should I do something with this pin?

Connect an LED + current limiting resistor. If the LED lights, the resonator is running. If the resonator is running, you can reprogram the processor; it's just a matter of getting the ISP bitrate low enough.

If the LED does not light, the resonator is not running and you will have to follow @dc42's advice: remove the resonator and provide a clock signal on XTAL1.

@dc42: Does the resonator have to be removed? Will it be damaged by a clock signal on XTAL1?

...am having a slightly big issue ...

A small issue?

You have set the "divide by 8" fuse. If you slow down programming you can probably talk to it.

Does the resonator have to be removed?

No.

@Coding Badley - the system runs at 3.3V, when selecting the current limiting resistor should I account for that voltage or a lower one?

@dc42 - I have Saleae Logic analyzer, should I be able to use that to test if there is a signal being outputted?

@Nick - Should I go lower than -B5 rate?

Thanks for the help everyone!

Aakash

Don't you need to connect the LED+resistor between the pin and ground, and then between the pin and Vcc, and check it lights in both cases? I wouldn't like to guess what state the CKOUT pin will have when there is no clock.

I don't think there is any danger of damaging the resonator if you leave it in place. However, the resonator will present quite a low impedance at frequencies that are not very close to its resonant frequency, and the signal from XTAL2 will provide negative feedback via the resonator to XTAL1. So it may be difficult to provide enough drive from the clock source, unless you match the resonator frequency. I guess it's worth trying with the resonator connected first.

Aakash:
@Nick - Should I go lower than -B5 rate?

-B5?

I set mine to run at 128 KHz and could reprogram it with -B250. So, no.

@dc42 - I have Saleae Logic analyzer, should I be able to use that to test if there is a signal being outputted?

I don't think that's relevant.

Have you reprogrammed the high fuse by any chance?

Aakash:
@Coding Badley - the system runs at 3.3V, when selecting the current limiting resistor should I account for that voltage or a lower one?

3.3V.

dc42:

[quote author=Coding Badly link=topic=132832.msg999568#msg999568 date=1353141095]Connect an LED + current limiting resistor. If the LED lights, the resonator is running. If the resonator is running, you can reprogram the processor; it's just a matter of getting the ISP bitrate low enough.

Don't you need to connect the LED+resistor between the pin and ground, and then between the pin and Vcc, and check it lights in both cases? I wouldn't like to guess what state the CKOUT pin will have when there is no clock.[/quote]

Ooh. Good point. LED needs to light both ways around to ensure the clock is running.

[quote author=Coding Badly link=topic=132832.msg999568#msg999568 date=1353141095]@dc42: Does the resonator have to be removed? Will it be damaged by a clock signal on XTAL1?

I don't think there is any danger of damaging the resonator if you leave it in place. However, the resonator will present quite a low impedance at frequencies that are not very close to its resonant frequency, and the signal from XTAL2 will provide negative feedback via the resonator to XTAL1. So it may be difficult to provide enough drive from the clock source, unless you match the resonator frequency. I guess it's worth trying with the resonator connected first.[/quote]

Is a series resistor between the clock source and XTAL1 pin necessary? A good idea?

Aakash:
@dc42 - I have Saleae Logic analyzer, should I be able to use that to test if there is a signal being outputted?

I'm not familiar with that device, but if you connect one of the channels to the CKOUT pin, then it should give you a frequency readout for that channel if there is a clock signal there.

As I've very little idea what sort of impedance the resonator will present, I would use one for safety, but only 100 ohms or so.

Nick,

I tried using -B250:

avrdude -p m328p -c avrispmkii -P usb -B250 -F

avrdude: stk500v2_command(): command failed
avrdude: stk500v2_program_enable(): bad AVRISPmkII connection status: Unknown status 0x00
avrdude: initialization failed, rc=-1
avrdude: AVR device initialized and ready to accept instructions
avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
avrdude: Expected signature for ATMEGA328P is 1E 95 0F

And regarding the high fuse question, I'm pretty sure. All I did was read in the fuse bits from the fresh chip and change the low bit by hand in AVR Studio. Though, I always could be mistaken.

@dc42 - I don't think CKOUT is outputting anything (see attached screenshot)

You won't measure an 8 MHz signal at an 8 MHz sampling rate.

Aakash:
@dc42 - I don't think CKOUT is outputting anything (see attached screenshot)

I think you're right, although you'll need to use a sampling frequency much greater than 8MHz to reliably see a 8MHz signal, so check with it set to 24MHz.

If you have an Arduino, you can use it to generate a clock signal to feed to XTAL1. Don't forget to use a potential divider to drop the voltage if it is a 5V Arduino.

PS - is it a 3-terminal resonator? If yes, have you grounded the centre pin? If no, are you certain that the capacitors you connected between the XTAL pins and ground are about the right value, and you haven't accidentally used a value that is much too large?

@dc42

I think the output looks the same at 24MHz. I have a 3.3V Arduino, what freq signal should I be generating to feed to XTAL1? Also, should I still try connecting XTAL1 and CKOUT?

And regarding your resonator question: It is a three terminal resonator. I didn't use my own caps as I believe they're built in. http://www.digikey.com/product-detail/en/CSTCE8M00G55-R0/490-1195-1-ND/584632

Thanks,
Aakash

EDIT: And yes, the center terminal is grounded.

The datasheet says that resonator has internal caps. I've use 8MHz ceramic resonators in my designs with no problems, although not at 3.3V and I set the low fuse byte to a more appropriate value.

Try feeding a clock signal from your 3.3V Arduino to XTAL1 through a 100 ohm resistor. The frequency doesn't matter much, I would try around 1MHz in the first instance. Leave CKOUT connected to your logic analyser so that you can check that you have a signal there.

Here's a sketch I use to get bursts of a known frequency on the OCR1A pin (pin 9 on an Arduino Uno):

// Generate a square wave of a given frequency on the OCR1A pin

#define REQUIRED_FREQUENCY  (38000)
#define REQUIRED_DIVISOR ((F_CPU/REQUIRED_FREQUENCY)/2)

#if (REQUIRED_DIVISOR < 65536)
# define PRESCALER  (1)
# define PRESCALER_BITS  (1)
#elif (REQUIRED_DIVISOR < 8 * 65536)
# define PRESCALER  (8)
# define PRESCALER_BITS  (2)
#elif (REQUIRED_DIVISOR < 64 * 65536)
# define PRESCALER  (8)
# define PRESCALER_BITS  (3)
#elif (REQUIRED_DIVISOR < 256 * 65536)
# define PRESCALER  (8)
# define PRESCALER_BITS  (4)
#elif (REQUIRED_DIVISOR < 1024 * 65536)
# define PRESCALER  (8)
# define PRESCALER_BITS  (5)
#else
# error Bad frequency
#endif

# define TOP        (((REQUIRED_DIVISOR + (PRESCALER/2))/PRESCALER) - 1)

void setup()
{
  pinMode(9, OUTPUT);
  digitalWrite(9, LOW);
  TCCR1A = 0;
  TCCR1B = (1 << WGM12) | PRESCALER_BITS;    // turn on
  TCCR1C = 0;
  OCR1AH = (TOP >> 8);
  OCR1AL = (TOP & 0xFF);
}

void on()
{
  TCNT1H = 0;
  TCNT1L = 0;  
  TCCR1A = (1 << COM1A0);
}

void off()
{
  TCCR1A = 0;
}

void loop()
{
  // Generate a burst 2ms long, then wait 10ms before generating the next one
  on();
  delay(2);  
  off();
  delay(10);
}