Programming a chip programmer with another chip programmer

Recently I had a need to program a few Atmel ATtiny chips for a project, which I haven’t done in years. I rummaged through my drawers and found the necessary programming device, which is a USBasp device:

image

When I tried using it to program an ATtiny chip using the standard programming software (avrdude), it showed an error suggesting that I need to update the firmware on the programmer device.

$ avrdude -cusbasp -pt45
avrdude error: cannot set sck period; please check for usbasp firmware update
avrdude error: program enable: target does not answer (0x01)
avrdude error: initialization failed, rc=-1
        - double check the connections and try again
        - use -B to set lower the bit clock frequency, e.g. -B 125kHz
        - use -F to override this check

But the programmer device itself uses an Atmel chip (ATmega8a) that is only programmable using another chip programmer. What to do? Rummaging further in my drawers, I discover this contraption:

image

It’s an extremely cheap CH341A programmer (~$2 on AliExpress) that I’ve used in the past to dump the contents of BIOS chips on motherboards and video cards. However, perhaps it can be useful here? Looking on the back of it, we can see that it can definitely do SPI (it has MOSI and MISO pins, although the latter is misspelled “MIOS”!). Could it be that this other programmer is also supported by avrdude?

image

$ avrdude -c\?
Valid programmers are:
...
  c2n232i            = serial port banging, reset=dtr sck=!rts sdo=!txd sdi=!cts
  ch341a             = ch341a programmer (AVR must have minimum F_CPU of 6.8 MHz)
  dasa               = serial port banging, reset=rts sck=dtr sdo=txd sdi=cts
...

How fortunate! So, what if we just connect all the relevant pins from this programmer to our target programmer that is receiving the update:

image
image

I connected the GND, +5V, MISO, MOSI, CLK (which goes to SCK), and CS (which goes to RESET) pins from the programmer to the target, remembering also to put a jumper on JP2 to enable self-programming. I also obtained the latest firmware to be loaded onto the chip. And here we go:

$ avrdude -cch341a -pm8 -b19200 -U flash:w:usbasp.atmega8.2011-05-28.hex
avrdude error: initialization failed, rc=-2
        the programmer ISP clock is too fast for the target
        - use -B to set lower the bit clock frequency, e.g. -B 125kHz
        - use -F to override this check

Hmm, something about the ISP clock being too fast… but it suggests that we can use -F to override this check. OK, let’s try that:

$ avrdude -cch341a -pm8 -F -U flash:w:usbasp.atmega8.2011-05-28.hex
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9307 (probably m8)
avrdude: Note: flash memory has been specified, an erase cycle will be performed.
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: processing -U flash:w:usbasp.atmega8.2011-05-28.hex:i
avrdude: reading input file usbasp.atmega8.2011-05-28.hex for flash
         with 4700 bytes in 1 section within [0, 0x125b]
         using 74 pages and 36 pad bytes
avrdude: writing 4700 bytes flash ...
Writing | ################################################## | 100% 1.25 s 
avrdude: 4700 bytes of flash written
avrdude: verifying flash memory against usbasp.atmega8.2011-05-28.hex
Reading | ################################################## | 100% 0.79 s 
avrdude: 4700 bytes of flash verified
avrdude done.  Thank you.

Wait, what? It worked! This is much easier than I thought it would be. Thanks, avrdude and cheapo CH341A programmer! I can now program ATtiny chips quickly and easily.

image