0
\$\begingroup\$

I accidentally changed the fuse bits on my ATmega644PA chip so that it is expecting a 32.768 kHz signal in the XTAL1/XTAL2 inputs. I am using the a USBTiny programmer (the Sparkfun AVR Pocket Programmer), which I read needs to operate at a clock speed slower than whatever clock the ATmega uses. I have access to a function generator, so I was thinking of generating a 32.768 kHz 5 Vpp clock and putting the positive end on the ATmega XTAL1 pin, and the negative end to ATmega GND pin. Is this the correct way to do things?

Also, how do I configure the programmer to use a much slower clock? I understand that the -B argument for avrdude specifies the clock period for the programmer. For instance:

avrdude -c usbtiny  -p atmega644p -B 250

would specify a 4 kHz clock. But from the avrdude help page, the -B option seems to specify the clock period only for JTAG (and whatever STK500v2 is), but I am using SPI.

 -B <bitclock>              Specify JTAG/STK500v2 bit clock period (us).

How exactly can I proceed to change the fuse bits back to using the internal calibrated 1 MHz clock?


EDIT:

The fuse accident happened when I erroneously flashed

-U hfuse:w:0xd9:m -U lfuse:w:0x24:m

which are the settings for atmega8, not atmega644p. What this did was make the clock input be "Low Frequency Crystal Oscillator" (i.e., expects a 32.786 kHz external clock), changed the SUTs, and finally, it disabled JTAG (JTAGEN bit, but I use no JTAG ports for programming so I do not think this is a problem).

When I finally am able to talk to the chip, I would like to flash the factory default ATmega644P fuses:

 -U lfuse:w:0x42:m -U hfuse:w:0x99:m -U efuse:w:0xFF:m -U lock:w:0xFF:m
\$\endgroup\$
  • \$\begingroup\$ Avrdude's -B option is what you want. It works for ISP, too. STK500v2 is Atmel's ISP programmer. \$\endgroup\$ – Janka Oct 5 at 17:50
  • \$\begingroup\$ You probably want -U lfuse:w:0xC2:m. \$\endgroup\$ – Janka Oct 5 at 17:55
  • \$\begingroup\$ @Janka, thanks... Why 0xC2? Is there a reason not to put the CLKDIV8 bit? Also, I tried connecting the 5Vpp signal generator output to XTAL1 the other end to the GND pin of the ATmega, and I used -B 250, but the atmega still does not respond (again, rc=-1 error). I think I am connecting the clock wrong, since the manual says there is an amplifier between XTAL1 and XTAL2. Did I damage the chip by inputting 5Vpp? \$\endgroup\$ – Carlos Vazquez Oct 5 at 18:02
  • \$\begingroup\$ Because you said you wanted back to 8MHz. Not 1MHz. \$\endgroup\$ – Janka Oct 5 at 18:03
  • \$\begingroup\$ @Janka, that was a mistake, I edited the question and also added the exact fuses that I mistakenly programmed in... One of the fuses I changed (disabled) is JTAGEN... Does STK500v2 use JTAG? And if so, does this mean that the chip cannot be programmed anymore? \$\endgroup\$ – Carlos Vazquez Oct 5 at 19:01

Your Answer

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

Browse other questions tagged or ask your own question.