Troubleshooting firmware flash using usbasp
  • I’m trying to program a blank Atmega328p with the DSP firmware for my DSP filter board. I’m using this USBASP programmer: https://www.amazon.com/Qunqi-Programmer-Adapter-ATMEGA8-ATMEGA128/dp/B014J2BMAG

    ...and a stripboard adapter like the ones described here: http://www.instructables.com/id/The-Idiots-Guide-to-Programming-AVRs-on-the-Chea/step3/Small-scale-MIG-welding-anyone/

    I’ve tested my programmer by writing a simple “blink one LED” program to an Atmega328p, which worked fine. I was able to successfully build the dsp firmware without any problems as far as I can tell, but I’ve run into a roadblock with avrdude flashing the chip. It looks like avrdude was able to set the fuses properly, but then fails to actually flash the hex file. Here’s the output:

    $ make -f dsp/makefile bake
    avrdude -V -p m328p -c usbasp -P usb -B 10 -e -u \ -U efuse:w:0xfd:m \ -U hfuse:w:0xd7:m \ -U lfuse:w:0xff:m \ -U lock:w:0x2f:m

    avrdude.exe: set SCK frequency to 93750 Hz
    avrdude.exe: warning: cannot set sck period. please check for usbasp firmware update.
    avrdude.exe: AVR device initialized and ready to accept instructions

    Reading | ################################################## | 100% 0.05s

    avrdude.exe: Device signature = 0x1e950f (probably m328p)
    avrdude.exe: erasing chip
    avrdude.exe: set SCK frequency to 93750 Hz
    avrdude.exe: warning: cannot set sck period. please check for usbasp firmware update.
    avrdude.exe: reading input file “0xfd”
    avrdude.exe: writing efuse (1 bytes):

    Writing | ################################################## | 100% 0.02s

    avrdude.exe: 1 bytes of efuse written
    avrdude.exe: reading input file “0xd7”
    avrdude.exe: writing hfuse (1 bytes):

    Writing | ################################################## | 100% 0.02s

    avrdude.exe: 1 bytes of hfuse written
    avrdude.exe: reading input file “0xff”
    avrdude.exe: writing lfuse (1 bytes):

    Writing | ################################################## | 100% 0.02s

    avrdude.exe: 1 bytes of lfuse written
    avrdude.exe: reading input file “0x2f”
    avrdude.exe: writing lock (1 bytes):

    Writing | ################################################## | 100% 0.02s

    avrdude.exe: 1 bytes of lock written

    avrdude.exe done. Thank you.

    avrdude -V -p m328p -c usbasp -P usb -B 1 \ -U flash:w:build/dsp/dsp.hex:i -U lock:w:0x2f:m

    avrdude.exe: set SCK frequency to 750000 Hz
    avrdude.exe: warning: cannot set sck period. please check for usbasp firmware update.
    avrdude.exe: error: program enable: target doesn’t answer. 1
    avrdude.exe: initialization failed, rc=-1 Double check connections and try again, or use -F to override this check.

    avrdude.exe done. Thank you.

    make: *** [bake] Error 1

    Every successive attempt to get avrdude to communicate with the ’328 in any way fails with that “target doesn’t answer” error. The only problem that I see are the warnings about failing to set the sck period. Maybe I really do need to get another usbasp to update the firmware, but it didn’t cause any problems in my original test flashes. Then again, I didn’t set the fuses during those tests.

    Any advice would be appreciated. I’ll be using the same setup to program a couple of ’644s with the control board firmware so I’d like to get this right.

    Edit: I read a little more about that the fuse settings do. So I guess the reason avrdude can’t talk to the chip anymore is that it’s set to clock off an external xtal. So I wired the 6 ISP pins from the PCB to my USBASP’s adapter and I think I’m good now. I guess to do it the way I was trying to, I need to flash the hex file first, then set the fuses afterward.

  • The warnings are okay, I think it is related to the fact that some USBasp’s have a fixed clock speed for the ISP communication that cannot be set by avrdude.
    I get these errors as well and never had problems with my homebrew USBasp.

    Once you set the fuses to use the external clock, the AVR needs a clock on its XTAL pins. If there is no clock present and the fuses are set for an external clock, the AVR will be effectively dead.
    Add the crystal and the two 22p load capacitors and it should work again.

    BTW: It doesn’t matter if you have the firmware programmed or not. The ISP communication for the programmer works independently from the firmware but it needs the main processor clock to be running. If you are programming the chip on the breadboard, with no external clock connected, you can of course flash the firmware first, then set the fuses and then install the chip on the board.

  • Thanks for the clarification. [=