So you may have been playing with Arduino's, or rather, Hackduino's. If you made your own Hackduino or similar project, you may be wondering how to add the ICSP header. Basically, using the ICSP header will allow you to use an external programmer to 'upload' software to your MCU (microcontroller unit). This will work for non-Arduino's nicely as well.

ICSP is basically "in circuit serial programming" which allows you to upload software to your MCU without having to pull it out every time.

So if you are pulling your MCU out each time you want to update the software on it and putting it into a programmer, or if you are just testing out your MCU and don't know what you're going to do with it yet, you can add the ICSP pins. If you have tried this before, but can't programme it, I will also tell you how to fix that from my own experience. If that isn't enough feel free to comment and I'll help you as best as I can!

By writing this Instructable (my first, by the way), I assume you have completed an instructable such as the following: https://www.instructables.com/id/Perfboard-Hackduino-Arduino-compatible-circuit/ - thanks jmsaavedra! This should, however, be compatible with any kind of breadboard-connected MCU or any other set up you have, too.

This Instructable tells you how to add a 6-pin ICSP header. The 10-pin header doesn't really add anything in ICSP mode. In step 3 you can also see the pinout for the 2x5 header, which works just the same. All you'd have to do is connect slightly differently - just follow the image and it'll work fine.

Below you will see my slightly unorganised remotecontrol repeater, but hey, it works :)

I'm a bit new to the world of electronics, so if you find a mistake please feel free to comment!

Step 1: Gather Components

First of all you need any kind of AVR controller and the datasheets that relate to it. You can download datasheets from www.atmel.com

Besides the AVR MCU and board, you will also need:
 - External programmer, such as STK 500, AVRISP or AVR Dragon
 - 2x3 pin header*
 - 2x3 connector, to connect to your external programmer**

You can actually just stick the MCU in a board, connect the pins as mentioned, and you can upload software to the MCU, too. Same method goes to PIC's, just check if it supports ICSP and where the pins are!

And of course some standard tools:
 - Soldering equipment (or a breadboard will work too, but the pins may be too short to fit properly!)
 - Some wire

* If you don't have a 2x3 pin header, but instead a single row pin, you can just solder two lines next to eachother in your perfboard.

** Simply using 6 F/F cables works, too, in case you don't have 2x3 connectors. 2x5 connectors will work too as long as you leave enough room. Be sure to position the cable correctly!

Step 2: Finding the Pins to Connect To

Got your datasheet ready? Great! We'll need it now. Go to the "Pin configuration" page.

Write down where the following pins on your MCU are:
 - SCK

This is the same for all equally-pinned AVR MCU's. That means if you have soldered an 28-pin IC socket you can safely replace the MCU with any other 28-pin variant (well, check the datasheet, I'm not a guru yet!). I tried this with a Atmega8 and Atmega328, which are both DIP-28. This should also be the same for Atmega168 and several others, so if you have any of those... simply use the image below.

We're going to connect our ICSP header to these pins, see the next step!

Step 3: ICSP Header Pinout

You can place your ICSP header basically anywhere on your breadboard or perfboard (or PCB),  simply connect the following lines to the pins you wrote down. Be sure to remember which side everything goes to.

This list is for 2x3 ICSP headers, if you want to use the 2x5 instead, see the image. It works just the same, but be sure to leave NC unconnected. Beware of the orientation!

Before proceeding please read the warning at the bottom of this page.
See the image below with the ICSP header pinout and do the following:
 - Connect pin 1 of the ICSP header to the MISO pin of your MCU.
 - Connect pin 2 of the ICSP header to your +5V supply on your board. So not necessarily to your Vcc pin on your MCU, simply put +5V on it.
 - Connect pin 3 of the ICSP header to the SCK pin of your MCU.
 - Connect pin 4 of the ICSP header to the MOSI pin of your MCU.
 - Connect pin 5 of the ICSP header to the RESET pin of your MCU (usually pin 1)
 - Connect pin 6 of the ICSP header to your ground (GND).

This takes some soldering and can be quite annoying, as the pins are quite near eachother. I'll spare you the sight of my perfboard's back view!

Now mark which is pin 1 near your ICSP header, and connect a cable to it.

Word of warning: if you connect your board to an external programmer through ICSP, 5V is put on pin 2! That means that this pin should directly connect to where-ever your 5V comes from (be it a 7805 or somewhere else). Your external programmer will automatically (usually) power your board through ICSP. 

So here is the catch, if you have an external programmer connected and you don't have a protection diode, the 5V from the programmer will flow into the battery or power supply. Be sure to connect either the ICSP - OR - a battery/power supply, and never both. You can prevent electricity flowing back by adding a diode just after your battery/power supply or you can add another 3-pin connector with a jumper so you can swap the power supply. However, that would be something nice for a next Instructable.

As electricity goes two ways, I recommend disconnecting the ICSP cable whenever you have your external programmer switched off. Power would flow into the programmer, and I don't really think that this is healthy for your programmer.

Step 4: Programming Through ICSP

Be sure no power is supplied to your board, and connect the other end of the cable to your external programmer, be it an STK 500, AVRISP or an AVR Dragon, or anything alike that has a 6 pin ICSP header.

If you are going to be programming through ICSP, you will bypass the Arduino bootloader which clears up some space.

You can use your STK 500 in AVR Studio to directly upload software to your board. This would mean you are not using Arduino at all, but just C and the AVR libraries. You can also use the Arduino studio. Just read this page to see how. Personally I am just programming it with C.

If your MCU isn't powering up, it probably means that your external programmer isn't putting +5V on your board. Don't worry, not all programmers do this! That doesn't mean you broke anything. If this is the case (please be really sure that your MCU is NOT powered at all, use a multimeter to see if there is +5V on pin 2 of the ICSP header), you can simply reconnect your battery or power supply. Then the programmer will work.

Generally the STK500 will put +5V on the pin, and the AVR Dragon won't. The pin is, however, still required to be connected, so that your programmer can detect your MCU. Be aware that the STK500 is externally powered, and the AVR Dragon only has the +5V from the USB port. It won't have enough juice to power an external circuit as well, as USB ports are limited to a certain current (500 mA or so). AVRISP is USB as well, but I'm not sure what this board would do. 

Step 5: (optional) Help! It Still Doesn't Work!

There are some possible reasons why your board still doesn't work. The most common reasons are:
 - ICSP is disabled on your MCU
 - you connected the pins wrong
 - there is a short somewhere in your circuit

Double check your pins first. Try to see if there is a short in your circuit by using a multimeter.

If that doesn't work it's possible that your MCU has ICSP disabled. You may have done this by accident, or it came from the factory with ICSP disabled. If you can upload software through it any other way, it's still possible that ICSP is disabled.

So if ICSP is disabled, what can you do? We're going to need to reset the chip. This would remove any software from it. We can do this by using something called High Voltage programming. Basically, we're going to put +12V on the RESET pin of your MCU. Well, we aren't, but your programmer is. Unfortunately the AVR Dragon / AVRISP can't do this (as far as I know), but the STK 500 can.

To see how to use high voltage programming with an STK500, see this page (at the bottom). Disconnect all ICSP cables from your STK500 and put your MCU in the appropriate socket (see the STK500 manual for where exactly). Set AVR Studio to PP/HVSP mode in "Main". Erase your device, and re-enable ICSP in AVR studio. This should be under Fuses in AVR Studio. Enable SPIEN and disable any lock bits (different tab).

If you want to know more about High Voltage programming, let me know!

Thanks for reading :)
<p>Hi nice article! How much space/flash saving are we talking about here? </p>
<p>For others new to programming Arduino in this manner, a brief primer:</p><p>The ICSP (In-Circuit Serial Programming) header implements the SPI (Serial Peripheral Interface) Bus and protocol.</p><p>The pins are, for the ISP6PIN header:</p><p>1 - MISO - Master Input, Slave Output - output from slave to master</p><p>2 - VTG - +VCC 5V</p><p>3 - SCK - Serial Clock - keeps the traffic in sync</p><p>4 - MOSI - Master Output, Slave Input - output from master to slave</p><p>5 - RST - Reset</p><p>6 - GND - Ground</p><p>http://arduino.cc/en/Reference/SPI</p>
Is there a standard (ISO or whatever) for the colors that the ICSP connector wires should have? I would like to color code my connector wires. <br> <br>thank you.
<p>If you use a 'rainbow' ribbon cable then the usual &quot;resistor colour code&quot; system applies:</p><p>Pin-1: Brown<br>Pin-2: Red<br>Pin-3: Orange<br>Pin-4: Yellow<br>Pin-5: Green<br>Pin-6: Blue</p>
When creating a circuit that requires ICSP capabilities can you still use the ICSP pins (D11-MOSI, D12-MISO, D13-SCK)? <br> <br>I had problems trying to reprogram an AVR setup with the basic blinking LED circuit on pin 19 (D13 - SCK) - removing the LED let the ICSP work fine. It probably makes sense that using these three pins for anything else could interfere with the reprogramming - but then that makes it quite a limitation, and one being very aware of. <br> <br>Obviously an option would be to have a jumper or TPDT (triple pole double throw) switch to change the circuit from being in &quot;run&quot; vs. &quot;program&quot; mode..
FWIW it seems 3PDT would be the right way to refer to what I meant - but thinking more I think I just need a 3PST switch. This can just disconnect whatever pins D11/12/13 are being used for, then the ICSP can be attached and will work fine.
hey there mate, im a little confused with ICSPs and have 1 question related to my problem. <br>Basically Im making a device that is using the arduino UNO with 3 differnt shields. All the digital pins have been used up and I need to find a way to save data on usb. <br> <br>So I was hoping to use the ICSP pins in order to save data using a USB shield like this one. Do you think it will work? <br>http://www.cooking-hacks.com/index.php/sd-card-shield-v2-1.html <br> <br>Also if it makes things easier, i've made my own USB socket https://www.instructables.com/id/Cheap-DIY-SD-card-breadboard-socket/ <br> <br>Do you think this can work? <br> <br>cheers for the help
Great instructable. <br>Just a question, though it might not be entirely in the scope of this product:<br>If I have a bootloader in this chip, what will ISP programming do? Will it just overwrite the bootloader?
Thanks! Basically, yes. If you use ISP to program your chip, anything on it gets overwritten, including bootloaders.<br><br>So if you use for example an Arduino, using ISP to program the chip will overwrite the bootloader, and you won't be able to use the Arduino IDE. You can just reprogram it with the bootloader, though. After that you are able to use the Arduino IDE again.<br><br>You can actually compile Arduino PDE's to a .hex file and use ISP to put that on the chip, then you have a chip that can't be programmed through the Arduino IDE as well. This saves some ROM and a little bit of start up time, but not really anything huge. This is a bit of a hassle in my opinion, though.<br><br>Enjoy!
Thanks for your extensive reply. That helps.<br><br>Now if you want to send a hex file to the arduino (the one that acts as ISP), I presuem you vannot do that through the Arduino software but rather you have to use AVRdude or something to send that hex file to the arduino who then sends it to the blank chip.<br>
Nice instructible, I would point out that 'ICSP' is (strictly speaking) a PIC thing, and is a Microchip trademark. I believe Atmel use 'ISP' (In-system programming). But I doubt anyone'll be suing you ;)

About This Instructable




More by barttech:Adding ICSP header to your Arduino/AVR board 
Add instructable to: