February 2012 &Although the procedure to use the Arduino as an In-System Programmer is well-documented, I thought it would be an interesting project to make a stand-alone programmer instead of having to link wires between two Arduinos. Designing the programmer from scratch meant I could tailor it to suit my own needs and avoid any documented problems such as the auto-reset fitted to later Arduino boards.
What follows is based on my own very limited experience with ATMEL microprocessors and will, no doubt, need modifying in the future in the light of additional knowledge.
The ATMEL In-System Programming MethodologyATMEL have a comprehensive guide to their In-System Programming so what follows is a quick summary as I understand the system.
The system uses the microprocessor's normal three-wire SPI bus (MOSI, MISO and SCK) to provide in-circuit programming by tri-stating (or, effectively, isolating from any other circuitry) all the chip's other IO pins during programming. This is achieved by holding the chip's RESET pin active (low) during the entire programming operation.
The programmer acts as Master on the SPI bus, so the timing of holding the RESET pin low is most-easily achieved by the programmer. Therefore, in addition to the three SPI lines between the programmer and the "target" chip, a fourth line from the programmer is used to control the RESET pin.
Thanks to work by David A. Mellis, Randall Bohn, Randall Bohn and others, in the Arduino environment, all this is taken care of for us with a sketch called ArduinoISP to be found in the Examples folder.
As the target microprocessor and an In-System Programmer are usually physically separate entities, a fifth line (Ground) is also required between them. The ATMEL AVR guidelines allow flexibility in how the target chip is powered. In my programmer, both programmer and target chip are on the same printed circuit board. As the power comes from the PC's USB port, that power is used to supply both the programmer and the target chip. A PCB-mounted slide swich can disconnect power from the target chip, if required, without it being necessary to power-down the entire programmer.
An outbound ISP header is provided on the programmer to enable it to be used as a "true" In-System Programmer. The header is 'outbound' in that the RESET connection (on header pin 5) is an outbound signal to the target's RESET input.
The Programmer Circuit
I've connected a yellow LED to the ATmega328's pin 19 (what would be the Arduino's "Hello World digitalPin 13"). I've also wired LEDs as recommended in the ArduinoISP sketch:
// Put an LED (with resistor) on the following pins: // 9: Heartbeat - shows the programmer is running // 8: Error - Lights up if something goes wrong (use red if that makes sense) // 7: Programming - In communication with the slaveA fifth LED shows when switch SW2 is supplying power to the "target" sockets.
Switch SW1 enables the Master's RESET to be controlled manually, with the PCB-mounted tactile push button switch, or automatically by using the DTR signal from the RS232R breakout board (The ByVac breakout board has a similar connection available). It's envisaged that the Master will require re-programming from time to time; for example, to run the Bootloader Sketch instead of ArduinoISP. Once the new sketch is in place, SW1 should be switched to the Manual position to prevent the ATmega328 resetting itself at inconvenient moments.