|This article needs additional citations for verification. (March 2015)|
In-system programming (ISP), also called In-Circuit Serial Programming (ICSP), is the ability of some programmable logic devices, microcontrollers, and other embedded devices to be programmed while installed in a complete system, rather than requiring the chip to be programmed prior to installing it into the system.
There are several incompatible in-system programming protocols for programming microcontroller devices such as PIC microcontrollers, AVRs, and the Parallax Propeller. ICSP has been primarily implemented by Microchip Technology for programming PIC and dsPIC devices.
The primary advantage of this feature is that it allows manufacturers of electronic devices to integrate programming and testing into a single production phase, and save money, rather than requiring a separate programming stage prior to assembling the system. This may allow manufacturers to program the chips in their own system's production line instead of buying preprogrammed chips from a manufacturer or distributor, making it feasible to apply code or design changes in the middle of a production run.
Microcontrollers are typically soldered directly to a printed circuit board and usually do not have the circuitry or space for a large external programming cable to another computer.
Typically, chips supporting ISP have internal circuitry to generate any necessary programming voltage from the system's normal supply voltage, and communicate with the programmer via a serial protocol. Most programmable logic devices use a variant of the JTAG protocol for ISP, in order to facilitate easier integration with automated testing procedures. Other devices usually use proprietary protocols or protocols defined by older standards. In systems complex enough to require moderately large glue logic, designers may implement a JTAG-controlled programming subsystem for non-JTAG devices such as flash memory and microcontrollers, allowing the entire programming and test procedure to be accomplished under the control of a single protocol.
For most Microchip microcontrollers, ICSP programming is performed using two pins, clock (PGC) and data (PGD), while a high voltage (12 V) is present on the Vpp/MCLR pin. Low voltage programming (5 V or 3.3 V) dispenses with the high voltage, but reserves exclusive use of an I/O pin. However, for newer microcontrollers, specifically PIC18F6XJXX/8XJXX microcontrollers families, entering into ICSP modes is a bit different. Entering ICSP Program/Verify mode requires the following three steps:
- Voltage is briefly applied to the MCLR (master clear) pin.
- A 32-bit key sequence is presented on PGD.
- Voltage is reapplied to MCLR.
A separate piece of hardware, called a programmer is required to connect to an I/O port of a PC on one side and to the PIC on the other side. A list of the features for each major programming type are:
- Parallel port - large bulky cable, most computers have only one port and it may be inconvenient to swap the programming cable with an attached printer. Most laptops newer than 2010 do not support this port. Parallel port programming is very fast.
- Serial port (COM port) - At one time the most popular method. Serial ports usually lack adequate circuit programming supply voltage. Most computers and laptops newer than 2010 lack support for this port.
- Socket (in or out of circuit) - the CPU must be either removed from circuit board, or a clamp must be attached to the chip making access an issue.
- USB cable - Small and light weight, has support for voltage source and most computers have extra ports available. The distance between the circuit to be programmed and the computer is limited by the length of USB cable - it must usually be less than 180 cm. This can make programming devices deep in machinery or cabinets a problem.
ICSP programmers have many advantages, with size, computer port availability, and power source being major features. Due to variations in the interconnect scheme and the target circuit surrounding a micro-controller, there is no programmer that works with all possible target circuits or interconnects. Microchip provides a detailed ICSP programming guide Many sites provide programming and circuit examples.
PICs are programmed using five signals (a sixth pin 'aux' is provided but not used). The data is transferred using a two wire synchronous serial scheme, three more wires provide programming and chip power. The clock signal is always controlled by the programmer.
Signals and pinout
- Vpp - Programming mode voltage. This must be connected to the MCLR pin, or the Vpp pin of the optional ICSP port available on some large-pincount PICs. To put the PIC into programming mode, this line must be in a specified range that varies from PIC to PIC. For 5 V PICs, this is always some amount above Vdd, and can be as high as 13.5 V. The 3.3 V only PICs like the 18FJ, 24H, and 33F series use a special signature to enter programming mode and Vpp is a digital signal that is either at ground or Vdd. There is no one Vpp voltage that is within the valid Vpp range of all PICs. In fact, the minimum required Vpp level for some PICs can damage other PICs.
- Vdd - This is the positive power input to the PIC. Some programmers require this to be provided by the circuit (circuit must be at least partially powered up), some programmers expect to drive this line themselves and require the circuit to be off, while others can be configured either way (like the Microchip ICD2). The Embed Inc programmers expect to drive the Vdd line themselves and require the target circuit to be off during programming.
- Vss - Negative power input to the PIC and the zero volts reference for the remaining signals. Voltages of the other signals are implicitly with respect to Vss.
- ICSPCLK - Clock line of the serial data interface. This line swings from GND to Vdd and is always driven by the programmer. Data is transferred on the falling edge.
- ICSPDAT - Serial data line. The serial interface is bi-directional, so this line can be driven by either the programmer or the PIC depending on the current operation. In either case this line swings from GND to Vdd. A bit is transferred on the falling edge of PGC.
An industry standard for using RJ11 sockets with an ICSP programmer is supported by Microchip. The illustration below represents information provided in their data sheets. However, there is area for confusion. The PIC data sheets show an inverted socket and do not provide a pictorial view of pinouts so it is unclear what side of the socket Pin 1 is located on. The illustration provided here is untested but uses the phone industry standard pinout (The RJ11 plug/socket was original developed for wired desktop phones).