1
\$\begingroup\$

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?

\$\endgroup\$
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – PeterJ Jun 18 '14 at 7:21
2
\$\begingroup\$

[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.

\$\endgroup\$
  • \$\begingroup\$ 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? \$\endgroup\$ – Ankit Jun 18 '14 at 8:33
  • \$\begingroup\$ atmel.com/images/… \$\endgroup\$ – Ignacio Vazquez-Abrams Jun 18 '14 at 8:42
  • \$\begingroup\$ 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. \$\endgroup\$ – Gerben Jun 18 '14 at 9:07
  • \$\begingroup\$ @Gerben: "A brand new AVR ..." "... when I [...] want to change the clock ..." \$\endgroup\$ – Ignacio Vazquez-Abrams Jun 18 '14 at 9:10
  • \$\begingroup\$ 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. \$\endgroup\$ – Gerben Jun 18 '14 at 9:14
1
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.