# Brand new ATmega8 - Changing Fuse Bits

I seem to have a little confusion regarding changing the fuse bits on a new ATmega8 AVR.

A brand new AVR comes with 1 MHz internal RC setting and there's no CKDIV8 fuse bit. Also since ISP programming should be done at less than 1/4th the speed of MCU, initially I have to program at < 250 kHz.

Now my question is when I plug in the AVR to the power source and wire up the SPI connections, and want to change the clock to 12 MHz external crystal do I first program the new fuse bit settings into the AVR (with no crystal connected) and then connect the 12Mhz crystal to the XTAL pins (along with the caps) or connect the crystal and then program the required fuse bits?

Also when one is programming an AVR, does it need a power source or does that come from the ISP header itself?

• I've only programmed the fuses with a crystal installed so that certainly works so it's probably easiest to include it from the start. For the second question though most programmers I've used don't power the target, but it'd be worth mentioning what you're using because some could be different. – PeterJ Jun 18 '14 at 7:21

[order]

Shouldn't matter. The AVR won't use the crystal until nRST is released, so you may as well hook it up first.

[power]

That depends on whether or not the programmer provides power. If it doesn't then you'll need to do so.

• Makes sense. So if my AVR is placed in the breadboard with the MISO and MOSI pins being connected to other components in my circuit, before programming do I need to disconnect them or I can leave them as it is? – Ankit Jun 18 '14 at 8:33
• atmel.com/images/… – Ignacio Vazquez-Abrams Jun 18 '14 at 8:42
• Not sure about the first claim you make. I've had a atmega8 I could not reprogram until I connected a crystal to it. So it does use the crystal in ISP programming mode. Still, the order shouldn't matter, in this case. – Gerben Jun 18 '14 at 9:07
• @Gerben: "A brand new AVR ..." "... when I [...] want to change the clock ..." – Ignacio Vazquez-Abrams Jun 18 '14 at 9:10
• Sorry. I forgot the NOT in my comment. The AVR in question was brand new. I could not program it without a crystal. I only later discovered how to set avrdude to program at a lower speed. – Gerben Jun 18 '14 at 9:14

Wire the crystal and caps to the virgin AtMega. Then make sure your ISP frequency is set to less than 1/4 the clock frequency as you suggest. Next program the appropriate oscillator select fuse. The AtMega will begin running at 12 MHz as soon as you program the fuse. Then you can boost the ISP frequency to 2 or 3 MHz to speed up erasing, programming & verifying the chip's flash memory.

Some programmers supply the AtMega with voltage, others don't, some have a jumper configurable option for either way. It's usually best to supply your own voltage rather than use the programmer's voltage source where you have a choice.

Some AtMegas have a dedicated GPIO pin which can be programmed via a fuse to output the internal clock frequency. It's usually a good idea to do this on a brand new breadboard to make sure you are getting the frequency you expect. Check it with an O-scope or freq counter.