I use the ArduinoISP example sketch to turn my Arduino Uno into an avrisp-compatible programmer, which I use to program other AVR microcontrollers with avrdude/avr-libc/etc. It works great!
Lately I've been working on a project that involves using ArduinoISP to program an ATtiny85. Like I said, it works great. Until I decided to set the ATtiny85's clock prescaler to 256. That is, I uploaded some code which, during its initialization, does this:
CLKPR = _BV(CLKPCE);
CLKPR = _BV(CLKPS3); // divide clock by 256
The fuses are configured to use the ATtiny85's internal clock source, which runs at 8Mhz, so with a 256 prescaler, the effective CPU frequency becomes 8Mhz/256 = 31.25kHz.
This is all well and good, and works as expected. The ATtiny85 runs very slow, and thereby conserves power. However, it is now too slow for me to program it! Avrdude can't even read the device signature anymore. I did not anticipate this
After searching around online, I found that it is apparently recommended not to set the SPI master's SPI clock to much more than 1/4 the clock of the SPI slave. In this case, the Arduino Uno, running ArduinoISP, is the master. My worry is that now its clock is much too fast compared to the clock of my ATtiny85, and that's why I can no longer program it.
Is this the case? I am kind of confused here. The 256 clock prescaler is only set when the ATtiny85 runs its user code... it's not set by fuses or anything (it couldn't be! fuses only let you set a prescaler of 1 or 8 ). I would have thought that when the programmer (ArduinoISP) brings the ATtiny85 into reset to program it, the ATtiny's clock would revert back to the full un-prescaled frequency, since it would not yet have executed the above CLKPR code. Or does the clock prescaler register carry over into the reset state?
In any case, if my problem really is that the ATtiny is now much too slow compared to the programmer, can anybody recommend a way to fix it? My guess is that I would have to make my Uno run equally slowly -- by setting its own CLKPR, and perhaps also by setting the SPR0 and SPR1 bits of its SPCR register... changing the Uno's CLKPR will of course bork all of the delay() calls (I guess I can dig into the Arduino headers and change F_CPU to compensate), and I'm kind of scared that making my Uno too slow will make it unprogrammable by its own bootloader -- does anybody know if this is the case?
Anyway, thanks for any suggestions!