ATtiny85: Played with CLKPR. now I can not program it

Hi all,

long time since I posted something in here.. Despite that, It seems I did not become any wiser :slightly_smiling_face:

I was playing around with the CLKPR register on an ATTiny85. My goal was to produce a 250KHz output on PB4. The ATTiny uses the internal 8MHz clock.
I accidentally set the CLKPR to 0111 that produced a ~62KHz output.

From that point on, I can not program the ATTiny any more. Actually I can not communicate with it at all.

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin>avrdude -C"C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf" -v -pt85 -cusbtiny -i 500 -Uefuse:r:-:i -Ulfuse:r:-:i -Uhfuse:r:-:i

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : usb
         Using Programmer              : usbtiny
         Setting isp clock delay        : 500
avrdude: usbdev_open(): Found USBtinyISP, bus:device: bus-0:\\.\libusb0-0001--0x1781-0x0c9f
         AVR Part                      : ATtiny85
         Chip Erase delay              : 400000 us
         PAGEL                         : P00
         BS2                           : P00
         RESET disposition             : possible i/o
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    12     4    0 no        512    4      0  4000  4500 0xff 0xff
           flash         65     6    32    0 yes      8192   64    128 30000 30000 0xff 0xff
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00

         Programmer Type : USBtiny
         Description     : USBtiny simple USB programmer, https://learn.adafruit.com/usbtinyisp
avrdude: programmer operation not supported

avrdude: Using SCK period of 10 usec
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.


avrdude done.  Thank you.


C:\Program Files (x86)\Arduino\hardware\tools\avr\bin>

The programmer I'm using is a sparkfun TinyAVR

The chip seems to operate, at least the PB4 outputs the 63KHz signal. There is no other code running:

void setup() {
  // put your setup code here, to run once:
cli(); // Disable interrupts
CLKPR = (1<<CLKPCE); // Prescaler enable
CLKPR = ((1<<CLKPS2)| (1<<CLKPS1) | (1<<CLKPS0));  // Clock division factor  (0111)
sei(); // Enable interrupts
}

void loop() {
 
}

Is there any way to revive it?

i couldn't find any exact description of this in the datasheet but it may be that the CPU is still running at 62.5kHz while you do that upload. Try to lower the upload rate by a factor of 128 (you may have to call the avrdude yourself to be able to do that).

You can try an HV programmer to factory reset fuses.

avr hv programmer - Google Search

I wonder what operation they are talking about. Maybe there is a problem in the "-Uefuse:r:-:i -Ulfuse:r:-:i -Uhfuse:r:-:i" part.
According to the documentation:

That will read the fuse bytes and write them in Intel-hex format to a file named "-"?!?

Note: The 'i 500' parameter to avrdude sets a 500-microsecond delay in the output pulses. If your system clock is very slow, you might recover by changing this to a higher value. I don't know where (or if) you get to specify it. My guess is either the "boards.txt" file or "programmers.txt" file for the ATtiny platform.

I do not really know what it refers to. The

avrdude: programmer operation not supported

comes up every time. Whether I'm programming a healthy chip, or when trying this one. So I just ignore it.

The "-" character is the representation of the "Standard Output". It just means write everything to the standard output (ie the screen in our case). It is a commonly used in Unix/Linux environment, where everything is a file, but it does work on windows too.

I tried with -B option of avrdude and set the CLK to 17uSec which corresponds to ~58.8KHz
Still I can not talk to the chip. also tried setting baud rate with -b option to 9600 but it did not help either.

Well, I prefer buying a bunch of new Tinys for the cost of the HV programmer :slightly_smiling_face: :slight_smile:
But the fuses are OK. This was just an example. The issue is to erase the eeprom, because it is there that the Prescaler gets the job done....

With the current Attiny85 prices that's going to be a challenge.

This is my 2 dollar HV programmer that piggybacks on a UNO. The little module is the 12 volt boost converter.

image

True that. Haven't realized their current prices. And your programmer looks way cheap. I just searched for a ready made and so 10ths of Euros, thats why I got disappointed.

Does yours erase the Flash memory as well? Because this is where my issue is. The Fuses were OK when I programmed it. It is the program in flash that makes it unresponsive...

Thanks everyone!

Edit: Corrected myself.

in that case I doubt if you even need the HV programmer. Your reset pin is still working as a reset pin I understand. And a disabled reset pin is the only thing a HV programmer can override for you.

I am starting to get curious and happen to have some Attiny25 laying around as perfect candidates to become victim of your program. It's just the sketch that you posted earlier? with the empty "loop()"?

1 Like

it is indeed. And the fuses are (or should be, as I can not read them right now, but these were the last time I burned them) lfuse: 0x22 hfuse: 0xdf efuse: 0xff

A long time ago I had exactly the same problem. On both an 84, and then stupidly also on an 85, I divided the clock by 256 in setup() meaning it was not possible to power the MCU, running the sketch, without slowing the clock. The slow clock prevented ISP access to the MCUs,

I got help in this thread and it worked a charm.

Maybe it will work for you.

I wrote your fuses settings to a T85 and then loaded your sketch. But I still can access the T85 with both my (flaky) USBTinyISP programmer as with a USBASP programmer I always use.
It was worth a try, but sorry that I can't be of any help.

1 Like

If you set the fuse that disables the Reset pin (to use it as an I/O pin) you will need to use High Voltage Serial Programming to clear the fuses.

Indeed it did!!! I left USBTiny and tried the Arduino as ISP. Changed the

#define SPI_CLOCK (128000/6)

and loaded the sketch to an UNO. I was then able to write an empty sketch to the ATtiny85.

Then I hooked the chip up to the USBtiny programmer again and I'm now able to read and program the chip.

Thank you all for the suggestions and the effort you put on it!!!! Much appreciated!!!

Good news. Enjoy.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.