USBasp – hints

The USBasp is a really useful and quit inexpensive ISP programmer that suits AVR 8 bit microcontrollers.

This article offers some hints on buying and using the USBasp.

There are lots of sellers of these on eBay, Aliexpress etc… but there are traps in buying them. I recall buying the USBasp with cable for less than $5, but they are more like double that now… or more.

Early versions of USBasp ran in a 4K chip, but the latest version requires an 8K chip. Do not buy one with a ATmega48*, but one with an ATmega8*.

They are almost always supplied with stale firmware, so you will want to upgrade it to 2011-05-28 (yes, it is old, but it is the latest) which supports the -B command line switch to slow down the SCK (see later discussion).

So, buy two, so you can use one to upgrade the other, and then switch them around and upgrade the second. If you have a spare Arduino Nano or the like, you could us it to build and run ArduinoISP (in the Arduino IDE examples folder) to do the once off upgrade of the USBasp.

Almost no one copies the original schematic exactly, in particular JP1, JP2 and JP3 from the original schematic might not be provided, and may have different designations. To upgrade one, you need to identify the equivalent to JP2, one pin of which is connected to the /RESET pin of the MCU, and JP2 must be connected for the entire upgrade process.

It is of advantage to buy one that has a shunt selectable 3.3V / 5V / NONE power to the target. Some have the facility using 0R pads on the PCB, but it is more convenient to use a shunt on header pins. One that has a plastic case probably does not allow changing the target power without breaking the case off.

You will probably buy one with the 10 pin ISP connector and cable on it, so buy a 10P/6P adapter as shown in the pic to suite the boards with the newer 6 pin ISP connector. The pic also shows two of those adapters with pogo pins inserted for programming boards that do not have the header pins installed and have either 6 PTH holes, or simply 6 pads. I have one of these 10P/6P adapters with the 6P locating key shaved off so it will fit one of the production Arduino boards (a UNO IIRC).

Some target boards do not have a keyed header shroud, be careful to establish correct orientation.

The USBasp shown in the pic has a shunt and header that allows selection of target power 5V, 3.3V or NONE.

WinUSB support of AVRDUDE and USBasp

I should mention an updated fork of USBasp that may be of interest to users of recent Windows versions: https://github.com/mariusgreuel/USBasp .

The combination of:

  • AVRDUDE for windows v7 or later from https://github.com/mariusgreuel/avrdude; and
  • updated USBasp with WinUSB support and WinUSB compatibility descriptor:  https://github.com/mariusgreuel/USBasp

work conveniently with driverless installation of the USBasp under Windows.

This combination seems to work well, I have upgrade all my USBasps to mariusgreuel’s firmware and use his for of AVRDUDE (including copying it into the AVRDUDESS, which I hardly use).

Upgrading

Most USBasp sold online come with stale firmware, so stale that they do not support the AVRDUDE -B option, and you want that feature. If you want to upgrade a USBasp, make sure you buy one with an ATmega 8A chip, some are sold with 4k chips and are too small for the current version of firmware.

The USBasp was designed to facilitate upgrade.

Above is the schematic of the original USBasp, note JP2 “self-programming” jumper. You must connect that for the entire duration of the upgrade process.

Now here is the problem, the jumper does not appear on many clones, it may or may not have header pins soldered on, and it may be called something else, JPx, but not JP2. This is the world of Chinese clones. The key thing is that this jumper connects pin5 of the output connector to the MCU /RESET pin. In the pic below, the jumper is labelled JP2 but has not header pins, so I use a little spring clip to connect them for this process.

So, locate the self-programming jumper and connect it.

AVRisp MkII to USBasp

Firstly I will show how to upgrade the firmware on a USBasp using an AVRisp MkII clone.

For an absolute beginner, I would recommend a clone AVRisp MkII which you can buy with cables and adapter on Aliexpress for less than $25 posted. It works with AVR Studio (Microchip Studio now) and AVRDUDE, it uses WinUSB driver which comes in Windows. If you happen to buy a modified one with the links to select target power of 3.3 or 5V, take the cover off and remove the link so it does not supply target power.

Above, the equipment hookup. The USBasp needs to be plugged into the USB power (a real AVRisp MkII does not supply target power), and the AVRisp MkII clone plugged into the 10pin header on the USBasp. If your AVRisp MkII has a 6pin plug, you need a 6p/8p adapter.

The other vital thing is that there is a link in the self-programming jumper as discussed above.

prg.bat

My preferred way of working is that the programming commands and parameters are encasulated in a Windows bat or cmd file as follows.

Using the AVRDUDE and the USBasp with Windows compatibility descriptor discussed above, we have a bat file.

@echo off

if *%PRG%==* set PRG=usbasp
echo PRG=%PRG%
if *%DEVICE%==* set DEVICE=m8
if *%PORT%==* set PORT=usb
rem if "*%OPTS%"==* set OPTS=-B 5

rem override
rem set PRG=usbasp
set DEVICE=m8
set PORT=usb
rem note -B requires latest (2011) USBASP firmware
set OPTS=
set AVRDUDE=avrdude

set FLASH=%1
if *%1==* set FLASH=bin\firmware\usbasp.atmega8.2018-06-25.hex

echo program flash (%FLASH%)...
echo on
"%AVRDUDE%" %OPTS% -c %PRG% -P %PORT% -p %DEVICE% -U flash:w:"%FLASH%":i
@echo off
timeout /nobreak /t 1 >nul
goto end

:usage
echo usage: %0 prg flashfile
goto end

:cleanup
:end

Though the bat file defaults to using a USBasp as the programmer, if we set environment variable PRG to avrisp2, the file will use that.

The console log from a single operation follows:

D:\src\USBaspW>set PRG=avrisp2

D:\src\USBaspW>prg
PRG=avrisp2
program flash (bin\firmware\usbasp.atmega8.2018-06-25.hex)...

D:\src\USBaspW>"avrdude"  -c avrisp2 -P usb -p m8 -U flash:w:"bin\firmware\usbasp.atmega8.2018-06-25.hex":i

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

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: reading input file "bin\firmware\usbasp.atmega8.2018-06-25.hex"
avrdude: writing flash (4646 bytes):

Writing | ################################################## | 100% 1.88s

avrdude: 4646 bytes of flash written
avrdude: verifying flash memory against bin\firmware\usbasp.atmega8.2018-06-25.hex:

Reading | ################################################## | 100% 1.55s

avrdude: 4646 bytes of flash verified

avrdude done.  Thank you.

Important things to check are that all the verify checks are correct and reconcile with the bytes written.

One of the very important benefits of this method of working is that it reduces the risk of writing wrong fuse bits to a chip, fuse bits that might make recovery very difficult. The batch file captures the important details of a particular application, and minimises the risk of finger trouble.

USBasp to USBasp

Upgrading is a bit of chicken and egg thing. You have to get the ‘old’ USBasp connected before you can use it to upgrade the second… so you need to sort out the driver issue. This is why I recommend starting with an AVRisp MkII or clone, clones sell for <$25 on Aliexpress.

ArduinoISP

I did not mention ArduinoISP because it does not deserve mention, too many traps for beginners.