I set REQUIRED_FREQUENCY (128000) and connected the logic analyzer to CLKOUT.

When connecting the source to XTAL1 nothing happens to CLKOUT. But when connecting it to XTAL2 the attached screenshot is the output.

EDIT: When D9 is connected to XTAL2, I ran this command "avrdude -c avrispmkII -p m328p -P usb -B250" and it still failed to initialize.

Very strange on several counts:

1. XTAL1 is the oscillator input, XTAL2 is the output. So it should be much easier to get a clock by injecting a signal into XTAL1 than into XTAL2. Are you sure you have nothing apart from the resonator connected to XTAL1? Is the 1.5K resistor still in place, or did you remove it?

2. Your photo suggests that you have a 128KHz signal on CLKOUT. However, you have the CKDIV fuse in place, according to your earlier post. So the CLKOUT frequency should be 1/8 of the input clock frequency, not equal to it.

3. With a 128KHz clock, you should be able to program the device via ICSP, as long as the high fuse byte hasn't been changed to disable ICSP programming.

I now understand why your resonator isn't oscillating. I was reading the CLKSEL bits the wrong way round. You have your clock fuses set to low-frequency crystal oscillator mode, which is intended for a 32768Hz watch crystal. This may also explain why XTAL1 and XTAL2 are not behaving as I expected.

So it might be worth trying an even lower clock frequency.

Nick, do you know what is the maximum -B parameter that avrdude works with? Maybe -B250 is too high?

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Could be, I programmed using the low-speed 128 KHz oscillator with that, but not with divide-by-8 set.

I don't know what its limits are, maybe divide 250 by 8.

Quote

I was reading the CLKSEL bits the wrong way round.

It is incredibly confusing the way they do that. If you "tick" the box in the fuse calculator, it sets the fuse to 0 (programmed). I think the reason is the default for EEPROM is to be 1 bits, so you "program" them by "setting" them to zero.

So if you uncheck all the boxes on the low fuse side, you get a fuse setting of 0xFF.

Please post technical questions on the forum, not by personal message. Thanks!

I've just read the avrdude command line options and I'm not sure that -B has any effect for atmega328p ICSP because it appears to be releveant to JTAG only. I also found the following:

Quote

-i delayFor bitbang-type programmers, delay for approximately delay microseconds between each bit state change. If the host system is very fast, or the target runs off a slow clock (like a 32 kHz crystal, or the 128 kHz internal RC oscillator), this can become necessary to satisfy the requirement that the ISP clock frequency must not be higher than 1/4 of the CPU clock frequency. This is implemented as a spin-loop delay to allow even for very short delays. On Unix-style operating systems, the spin loop is initially calibrated against a system timer, so the number of microseconds might be rather realistic, assuming a constant system load while AVRDUDE is running. On Win32 operating systems, a preconfigured number of cycles per microsecond is assumed that might be off a bit for very fast or very slow machines.

So I suggest you try adding e.g. -i 100 or -i 500 or even more to the avrdude command line, while driving it with that 128kHz clock.

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

- with 128kHz applied to XTAL2 you are getting 16KHz on CLKOUT- so you need to program it with SCLK not exceeding 4KHz- so -B 250 is barely enough cycle time, if avrdude does use the -B parameter to set the SCLK rate of the AVRISPmkII

So try with 128KHz applied to XTAL2 again, but this time:

- try avrdude with a -B parameter greater than 250- try using AVR Studio, with the SCLK frequency in the user interface set to 4KHz or even lower.

If that fails, try with 32768Hz or so applied to XTAL1 or XTAL2 (whatever gives you a clean CLKOUT signal) and use SCLK <= 1kHz in AVR Studio. The docs say you can't program the flash below 2KHz, but you can do a chip erase.

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

To get an extra slow SCK you may need to use something else for programming.

I find the slow clock setting on a USBasp often does the trick whenever things get a bit stubborn. For $5 or so on ebay, I think one of these is a reasonable investment for anyone who does more than the most infrequent ICSP programming.

- with 128kHz applied to XTAL2 you are getting 16KHz on CLKOUT- so you need to program it with SCLK not exceeding 4KHz- so -B 250 is barely enough cycle time, if avrdude does use the -B parameter to set the SCLK rate of the AVRISPmkII

So try with 128KHz applied to XTAL2 again, but this time:

- try avrdude with a -B parameter greater than 250- try using AVR Studio, with the SCLK frequency in the user interface set to 4KHz or even lower.

If that fails, try with 32768Hz or so applied to XTAL1 or XTAL2 (whatever gives you a clean CLKOUT signal) and use SCLK <= 1kHz in AVR Studio. The docs say you can't program the flash below 2KHz, but you can do a chip erase.

Yep! That worked. I set the clock source (D9) from the Arduino to 128KHz and connected it to XTAL2. After that, I went into AVR Studio and set the rate to 4.209KHz (or something very close) and the connection was very unstable. Though, I was able to set the fuses back to factory state after trying to write them a few times. Now it's working without the external clock source!

I'll try to write the low fuse to use the resonator tomorrow, or sometime soon, but correctly this time :-)