23 May 2013

How to Do ISP Programming – Part 2: Hardware Considerations

What Hardware do I need?
Obviously you need the controller. This can be any Atmel ATtiny or ATMega. You need a circuit board to put the controller in (the "target board") and you need an ISP programmer. Since ISP uses a serial format, the programmer can be rather compact.

There is a wide variety of programmers on the market, from full featured expensive to cheap and simple. Since this tutorial is targeted at beginners, who don't want to risk a lot of money for their first steps, I will describe using one of the cheapest options here.
And that option is a programmer called USBasp. It is a great open-source project by Thomas Fischl. The programmer is connected to the USB bus of a PC and has an ISP cable on the other end. It is supplied through the USB bus, so no external power supply is needed.
The project is so popular, that it is widely used and supported by many software environments. And some Chinese companies saw a business opportunity and are now offering the ready made programmer for very little money. I wrote a review on this earlier.

How to connect
As mentioned in part 1 of this tutorial, you need only a few lines to connect your ISP programmer to the target board. There is the serial interface, comprising MISO, MOSI and SCK pins, there is the RESET pin and there are the power supply lines Vcc and GND. Here are two examples how the connections have to be made. The first one is from an earlier post. I is for the ATMega8:

The second example is for the ATtiny13:

Power Supply
The programmer is supplied through the USB port. This is good. But there is something to look out for. The ISP connector has a Vcc pin. This can be used in two ways. Either, the programmer can supply the target board, or the target board can supply the programmer. Since the USBasp programmer has its own supply, the second option makes no sense for us.

WARNING: If your target board has its own supply, DO NOT CONNECT THIS PIN. Otherwise you have two supplies working against each other! This could destroy your hardware. In many cases I do use the programmer to supply my target board. It is usually quite convenient.

Hint: Some USBasp variants have a dedicated jumper to disconnect the power supply from the programming cable. In that case you can connect Vcc and connect / disconnect it via that jumper. 

SCK Clock Issues
When programming an AVR controller via ISP there are two clocks involved. First, there is the system clock. In order to keep things simple, the standard system clock is used for this, just like during normal operation.

The second clock is the SCK. This is a shift register clock, which is used to move serial data into and out of the serial interface. There is a very important condition: The frequency of SCK must be less than one quarter of the system clock. 

So if for some reason your programmer cannot communicate with your target, check whether this condition is met.
And there is something else that you have to know about the USBasp project: Older versions of the programmer's firmware used a very simple scheme to set SCK. The standard frequency was 375 kHz. This would only work for system clock frequencies over 4 x 375 = 1.5 MHz. But many AVRs come with a preset frequency of 1 MHz (e.g. ATMega8: Internal RC oscillator with 8 MHz, but CKDIV8 fuse is set, i.e. the system clock is divided by 8).

So in order to slow down SCK the project initially used a jumper ("J3"), which would reduce the clock frequency to 8 kHz when set. Later versions of the firmware can set the frequency by software.

The only problem is that some Chinese programmers still come with the older firmware version. And avrdude doesn't like that. It throws a warning:

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

Don't panic. Programming should still work, as long as the SCK frequency isn't too high for you target. If it is, you have to set J3.

In the next part we look at the software and how to use it.


  1. hello i have this USBasp http://www.easytechnology.gr/index.php?main_page=product_info&cPath=3_14&products_id=1534&page= and its a new varsion and does not have the slow clock jumper. This is because you can now set the slow clock using the AVRdude -B option how can i do this?

    1. Yes that should be the case. Please read part three for details - out now. :-)

      27€, seriously?

  2. yes :) i live in greece thank u very much about your help. alex

  3. Thanks again Tom. The fog is beginning to clear.

    Looking at that diagram for the ATtiny above, there are only 2 pins not involved in programming. But I assume at least some of the other pins can be used when not programming. Which can be used, which can't, which can only be made use of if I have a high voltage programmer? What are the limitations of using those pins that are also programming pins? Do I need to use jumpers on all those pins, or can I get away without them with careful design?

    1. Paul,
      With HV programming you take the chip out of the target board, so you can use all pins as you like.

      With ISP programming on the other hand, you have to look a bit closer. Reset is always necessary. MISO, MOSI and SCK can be used, but should be used as outputs. Because if some peripheral electronics is driving those pins during programming, the programmer is driving them at the same time so it won't work.

      As you say, jumpers would help. Alternatively, You could add resistors in front of the pins. The peripheral electronics could then be overwritten by the programmer. Time for part 5 of this tutorial? ?...