avravrdudeattiny

Failing to access AVR ATTiny13A with very slow clock (128kHz/128 or 128kHz/256) (avrdude: error: program enable: target doesn't answer)


I am trying to program an AVR ATTiny13A using a USBasp adapter (guloprog) and avrdude. Uploading the program and running it works fine the first time for a fresh ATTiny13A device, but re-uploading again fails. avrdude cannot see/access the device at all. avrdude behaves like the device is not connected.

>avrdude -c usbasp -p t13 -B120 -U lfuse:r:-:b 

avrdude: set SCK frequency to 8000 Hz
avrdude: error: program enable: target doesn't answer. 1 
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

avrdude done.  Thank you.

If I reduce the communication speed to the minimum supported by avrdude

>avrdude -c usbasp -p t13 -B2000 -U lfuse:r:-:b 

I get set SCK frequency to 500 Hz with the same result as above.

Looking at the programming signals with an oscilloscope, all signals look good, except for MISO which only shows rudiments of communication between 0V and 0.2V.

I have set the CKSEL fuses to 11, selecting the internal 128kHz clock source. In the program I set CLKPR to 8, dividing the 128kHz clock by 256, to get the slowest clock possible. (I have also set CKDIV8 to 1, but that should not matter.)

Have I fuse-bricked the IC? I do not have a HVSP to clear the fuses. What else can I do?


Solution

  • How to unbrick the AVR with a very slow clock divider setting

    The problem is caused by writing CLKPR with a very slow clock divider setting (/128 or /256 with the 128kHz clock) in the program. After the program started, programming no longer works (regardless of the -B setting for avrdude).

    Solution without HVSP (with pull-down resistor): Put a pull-down resistor between RESET and GND (10k worked for me). Now you can access the AVR again and program a different program, setting the clock divider to at most /64.

    The pull-down resistor will keep the AVR in reset after power-up, not allowing the program to run, preventing the slow clock to be set. In order to run the new program you need to remove the pull-down resistor.

    Alternative solution with HVSP

    If you have a HVSP you can reset the CKSEL to 10 again to use the 9.6 MHz internal clock (and potentially set CKDIV8 to 0 again). This will allow you to access the device again.

    Background

    avrdude limits the slowest communication speed to a minimum of 500 Hz. This is hardcoded in the source, see https://github.com/avrdudes/avrdude/blob/5cbc9c37fc71c424e99bdcc00bb910fd581c2676/src/usbasp.c#L903

    The device must be clocked at least four times faster than this speed. For 500 Hz communication speed this means that the AVR must run at 2000 Hz or higher. This means that the slowest clock-divider setting with the 128kHz clock which is compatible with avrdude is 128kHz/64 = 2000Hz (and this is already on the edge and may fail, but it worked well for me). To get the slowest avrdude communication speed (500 Hz) use the -B 2000 option, e.g.:

    avrdude -c usbasp -p t13 -B2000 -U lfuse:r:-:b
    

    which works:

    avrdude: set SCK frequency to 500 Hz
    avrdude: AVR device initialized and ready to accept instructions
    
    Reading | ################################################## | 100% 0.15s
    
    avrdude: Device signature = 0x1e9007 (probably t13)
    avrdude: reading lfuse memory:
    
    Reading | ################################################## | 100% 0.05s
    
    avrdude: writing output file "<stdout>"
    0b1101011
    
    avrdude: safemode: Fuses OK (E:FF, H:FF, L:6B)
    
    avrdude done.  Thank you.
    

    Uploading programs will be very slow, but for programs which are only a few instructions long this is feasible.