Introduction: Adding ICSP Header to Your Arduino/AVR Board
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!
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!
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:
- RESET
- SCK
- MOSI
- MISO
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!
Write down where the following pins on your MCU are:
- RESET
- SCK
- MOSI
- MISO
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.
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.
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 :)
- 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 :)