This is only a preview of the October 2002 issue of Silicon Chip. You can view 28 of the 96 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Articles in this series:
Items relevant to "Speed Controller For Universal Motors":
Items relevant to "PC Parallel Port Wizard":
Items relevant to ""Whistle & Point" Cable Tracer":
Items relevant to "Build An AVR ISP Serial Programmer":
Purchase a printed copy of this issue for $10.00. |
Upload your microcontroller code in seconds with this
new, PC-serial-port-connected programmer design.
AVR ISP Serial
Programmer
This project will allow you to erase and rewrite the program
and data memory in your AVR micro in a flash – without
even removing it from the application circuit.
Design by STEPHEN DAVIES
Words by PETER SMITH
72 Silicon Chip
www.siliconchip.com.au
B
ack in the October 2001 issue
of Silicon Chip, we described
an AVR ISP programmer with
similar capabilities to those detailed
here. The original design connects
to your PC’s parallel port, with just
one low-cost IC providing buffering
between the SPI interface and parallel
port lines. The emphasis of the design
was on ease of construction and low
cost.
This new design is slightly more
complex but it provides a number of
useful additional features.
For a start, most PCs have a free
serial port, whereas the parallel port
may already be used for a printer or
scanner. Serial port interfaced devices
are generally much more robust, too;
there are no issues with inserting and
removing the connector with power
applied, and cable length is relatively
unimportant.
Best of all, support for the AVR ISP
Serial Programmer is already built
right into AVR Studio. This means
that you can assemble, debug and then
program your AVR micro, all within
the same application. By contrast, the
October 2001 design needs a separate
application to perform the programming part of the cycle.
AVR Studio, by the way, is a complete set of PC-based development
tools for use with Atmel’s AVR microcontroller family. It includes a project
manager, source editor, assembler and
simulator – and it’s free!
Serial versus parallel
programming
A potentially confusing aspect of
AVR programming involves the terms
“serial” and “parallel”. Most AVR
devices can be programmed using
a low-voltage “serial” method or a
high-voltage “parallel” method.
With serial programming, the RESET pin is held low while data is
exchanged over a 3-wire Serial Programming Interface (SPI). No special
programming voltages are required;
the microcontroller’s supply pin
remains within its normal operating
range (usually 2.7-6.0V).
Conversely, with parallel programming, the microcontroller must be
supplied with 5V whilst the RESET
pin is driven to 12V. In addition, eight
bits of data are transferred simultane-
ously rather than the bit-by-bit transfer
of the serial mode. In all, fourteen
distinct signals are required in parallel
programming mode, making it considerably more difficult to implement.
In-system programming
The advantage of the low-voltage
serial programming method is that it
allows in-system programming (ISP).
In-system programming means just
that. There’s no need to even remove
the AVR micro from its socket in order
to reload program and/or data memory. In many cases, all you need to
do to make use of this feature in your
designs is provide a connection point
(the ISP header) for the programmer.
The block diagram in Fig.1 shows how
it all hangs together.
Fig.2 shows how the ISP header
would be hooked up in a typical design. The AVR micro shown in this
example uses the same pins for both
the SPI signals (MOSI, MISO and SCK)
and the upper port B I/O signals - PB5,
PB6 & PB7. During normal operation,
these three pins behave like all the
other port I/O lines. However, when
RESET is held low, the alternate SPI
Fig.1: the programmer
connects between
your PC and the
target board. Power is
provided by the target
board, thus eliminating the need for a
separate supply.
www.siliconchip.com.au
October 2002 73
Fig.2: most AVR
micros can be
programmed via
a 3-wire Serial
Programming Interface
(SPI). It’s just a matter of wiring the SPI signals to a header for connection
to our programmer. In some cases, you may also need to add three 1kΩ
resistors, as shown here.
function is selected and programming
operations can commence.
Notice the three 1kΩ resistors in
Fig.2. They provide a measure of isolation between the user circuits and the
SPI signals. This works well if the I/O
pins are used for inputs only or when
used for outputs, if they only need to
sink or source a few mA of current. A
universal solution is shown in Fig.3,
where the user circuits are isolated with
an analog multiplexer when in programming mode (RESET signal low).
Of course, the simplest solution of
all would be to incorporate jumpers
or DIP switches in the design, so that
the user circuits can be completely
disconnected from the port pins when
the programmer is connected.
in-system programming.
Fuse bits
How it works
At this point, you’re probably
wondering why we need the parallel
programming method at all. Serial
programming does the job, with fewer
signals and at a lower voltage, doesn’t
it? Well, yes - almost. The fuse bits on
most devices can only be programmed
with the parallel method.
Fuse bits are used to control several
important microcontroller features.
They can be thought of as non-volatile
switches. When on, the respective
feature is enabled and when off, it is
disabled.
Fuse-selectable features vary according to device, so check your micro’s data sheets for details. In most
cases, the factory-programmed fuse
settings are fine for general use, so
this serial programmer is probably all
you’ll ever need!
By the way, all AVR devices, with
the exception of the AT90S8534,
ATTiny11 and ATTiny28, support
As you can see from the circuit diagram in Fig.4, there really isn’t much to
the hardware side of the AVR ISP Serial
Programmer. Most of the hard work is
done by IC2, an AVR microcontroller.
The design incorporates two serial interfaces. One connects to your
PC’s serial port and the other to the
SPI port on the microcontroller to
be programmed. Conceptually, the
microcon-troller (IC2) can be thought
of as an intelligent “bridge” between
these two interfaces. As you’ve prob-
74 Silicon Chip
ably guessed, this “bridge” is needed
because PC serial ports and SPI ports
are entirely incompatible.
Data is sent and received over the PC
serial port lines at RS232 voltage levels
(up to +/-12V). Translation to standard
TTL levels (0 – 5V) is performed by IC1,
a MAX232. This device incorporates
a charge pump voltage doubler and
inverter for generation of the required
positive and negative voltages, hence
the need for the 1uF capacitors.
Unlike the PC interface side, the
Serial Programming Interface operates at TTL voltage levels (0 – 5V).
The SPI consists of three signal lines,
namely: MOSI (Master Out Slave In),
Fig.3: an analog multiplexer can be used to completely isolate the user
circuits during programming
Table.1: Supported devices
ATTiny12
ATTiny15
AT90S1200
AT90S2313
AT90S2323
AT90S2343
AT90S4414
AT90S4433
AT90S8515
AT90S8535
Atmega83
Atmega103
Atmega161
Atmega163
MISO (Master In Slave Out) and SCK
(Serial Clock).
The microcontroller (IC2) is considered the serial bus “master”. It controls
the SCK line, sending serial data on
MOSI and receiving data on MISO. It
also controls the target micro’s RESET
line, driving it low to activate SPI
(programming) mode.
Connection to the target board is
made via a 6-pin single-row header
(CON3) or a 10-pin dual-row header
(CON2). Pinouts for both headers are
shown in Fig.5. The 10-pin header
is optional. We’ve included it in the
design because it tends to be the most
common type in use on AVR development boards.
Low-voltage operation
Power for the programmer is derived
from the target board. As shown, the
programmer is designed to operate
from 4.5-5.5V. However, some microcon-troller variants can operate
over a much wider voltage range.
For example, the AT90S1200-4 and
www.siliconchip.com.au
+V
C1
1F
C2
1F
R1
10k
2
6
16
Vcc
C1+
Vq
C1q
C3
1F
C2+
CON1
8,10
14
3
Tx
7
5
Rx
13
1
RS232
TO PC
SERIAL
PORT
2
7
8
T1out
IC1 C2q
MAX232
T1in
T2out
T2in
R1in
R1out
R2in
20
1
V+
R2out
1
C4 1F
RES
3
4
C5 1F
5
11
PB7
11
9
10
6
12
3
9
2
PD6
PD3
PB3
PD2
PB2
PD1/TxD
SC
PB1
PD0/RxD
PB0
GND
X2
4
6
2002
PB6
PD5
GND
15
JP1 IN: BOOTSTRAP
PROGRAMMING
OUT: NORMAL
D1
1N5817
4 x 100
SCK
7
MISO
9
17
MOSI
1
RESET
5
C6
22pF
15
14
13
4,6
8,10
JP1
CON3
ISP
12
10
4MHz
2
RES
5
4
5
1
TO
TARGET
BOARD
3
C7
22pF
AVR ISP SERIAL PROGRAMMER
TO
TARGET
BOARD
3
X1
X1
CON2
ISP
(OPTIONAL)
VCC 2
A
18
19
IC2
PB5
AT90S1200
8
16
OR
PD4
PB4
AT90S2313
7
K
C9
10F
16VW
Vcc
RES
4
9
C8
100nF
6
1N5817
A
K
Fig.4: the complete circuit diagram for the programmer. IC2 drives the target micro’s SPI lines in response to
commands and data received from the PC serial port.
AT90S2313-4 are specified for 2.7 –
6.0V. Higher speed devices such as the
AT90S1200-12 and AT90S2313-10 are
specified for 4.0 – 6.0V only.
If you’re likely to be using the programmer with designs powered from
less than 4.5V, then several points
need to be considered. Firstly, you’ll
note that we haven’t specified a speed
rating for IC2 in the parts list. Any
speed device (-4, -10 or -12) will work
OK in the programmer if the target
board supplies between 4.5 and 5.5V.
However, for low-voltage operation,
you should choose the –4 (4MHz) part.
In addition, you will need to replace
IC1 with a MAX3232 (or equivalent)
device, suitable for operation down
to 2.9V. By the way, we’ve nominated
2.9V instead of 2.7V, as this is the minimum programming voltage shown in
Fig.5: pinouts for the two ISP header
variants. Use the same pin assignments for your designs.
www.siliconchip.com.au
the most recent Atmel errata sheets.
Finally, you’ll need to replace D1
with a wire link. Although we’ve
specified a Schottky diode here, even
its 0.2V drop will be too high at these
low voltage levels. D1 provides reverse
polarity protection but is unnecessary
if you use the specified header sockets
and plugs. These are polarised (keyed)
and therefore impossible to accidentally reverse.
Having said all that, we believe that
the programmer will probably func-
tion right down to 2.9V even without
the lower-voltage components. No
guarantees though!
Microcontroller choices
This project is based on Atmel’s
application note AVR910. Atmel’s
original design calls for an AT90S1200
device for IC2. We’ve retained support for this device, and included
the option of using an AT90S2313 as
well. The latter device is a little more
expensive, but we believe that some
The PC board is a snug fit inside the case - so snug, in fact, we didn’t worry
about any mounting screws. Your PC board might need some minor surgery on
the corners (with a file) to ensure it fits past the case corner pillars.
October 2002 75
Fig.6: the overlay
diagram with
full-size PC board
pattern shown
“ghosted” underneath. The two
pads above CON2
are for temporary
connection to an
external 5V DC
supply (needed
only during
bootstrap
programming).
a kit, then there is no need to install
JP1. This 2-pin header and its associated jumper shunt are only required for
bootstrap programming, which we’ll
look at shortly.
Cable assembly
A minimum of two cables is required for a working setup, so we’ll
describe them first. For connection
to your PC’s serial port, you’ll need a
length of 9-way IDC cable with a 9-pin
male ‘D’ connector on one end and a
10-way header plug on the other. Cable
length is not critical and can be up to
1.5m or more. Fig.7 shows the details.
For connection to your target
boards, a much shorter length of 6-core
data cable or 6-way rainbow cable is
required. We recommend a maximum
length of about 250mm. Each end
should be fitted with a 6-way header
plug, wired pin to pin (see Fig.8).
If you own one of the many development boards that use 10-way headers
for the ISP connection, then you’ll
want to make the optional 10-way
cable. All that’s required is a 250mm
length of 10-way IDC cable with an
IDC header plug on either end.
Bootstrap programming
This photograph of the completed PC board is actually larger-than-life so you
can clearly identify the components and their placement.
enthusiasts will already have a spare
one or two of these in their parts bin!
The AT90S2313 is pin-compatible
with the AT90S1200 but includes
extra goodies such as SRAM, a UART
and more program (Flash) memory.
The designer has modified Atmel’s
original program so that it will run
on the AT90S2313 but a little more
on that shortly.
Construction
Referring to the overlay diagram in
Fig.6, begin by installing the three wire
links. Next, install all of the resistors
followed by diode D1. Be sure to align
the cathode end of D1 (indicated by a
white band) as shown.
The remaining components can be
installed in any order you wish but
leave the crystal (X1) and the connectors (CON1 – CON3) until last. CON1
and CON3 (optional) should be aligned
with pin 1, or the polarised side, facing towards the middle of the board.
When soldering, make sure that the
connectors are seated firmly against
the PC board surface.
76 Silicon Chip
The crystal (X1) is mounted in the
vertical position. Once in place, use a
length of tinned copper wire to attach
the body to the ground pad underneath, shown marked with an asterisk
(*) in Fig. 6.
Note that if you have a pre-programmed microcontroller (IC2), as
would be the case if you’ve purchased
Fig.7: the RS232
cable is made up
using two crimpstyle IDC connectors.
Note that the header
plug has one more
pin than the ‘D’
connector does.
This is easily
handled by
crimping the
header plug
first, then
stripping
back the 10th
conductor and
snipping it off where
it enters the header.
As with any other micro project, the
program (Flash) memory in IC2 needs
to be programmed before it will perform as designed. If you’ve purchased
this project as a kit, then the micro
will already be programmed. You
should skip this section and go directly to “Housing”. However, if you’ve
sourced all the bits individually, then
Fig.8: connection from programmer
to target board is via one of these ISP
cables.
www.siliconchip.com.au
you’ll need to program IC2 yourself.
The program files for IC2 are available from the Silicon Chip web site at
www.siliconchip.com.au If you have
an AT90S1200, then download the
AVR910a.ZIP file. Alternatively, for
an AT90S2313, download AVR910b.
ZIP. Inside these .ZIP files you’ll find
both the assembled (.HEX) file ready
for upload to the micro as well as the
source (.ASM) file.
If you have access to another (working) ISP programmer, simply connect
it to one of the ISP headers (CON2 or
CON3), hook up an external 5V DC
supply and you’re ready to upload
the code. We’ve provided a convenient connection point for the external
supply in the form of two spare pads,
situated just above CON2. Refer to the
overlay diagram (Fig.6) for details. Oh,
and you’ll need to install a shorting
link on JP2 during programming, too.
Don’t have access to a working programmer? No problems – we’ve devised
a method of “bootstrap programming”
IC2 to cater for this very dilemma!
You’ll need a free parallel port on your
PC, a “bootstrap programming” cable,
an external 5V DC <at> 50mA power
source and Windows programming
software. Let’s make the cable first.
Using a 450mm length of data cable
or rainbow cable, solder a 25-pin male
‘D’ connector to one end and a 6-way
header socket to the other. Fig.9 shows
the pin connections. For connection
to an external power source, solder
two lengths of hook-up wire to the
spare pads situated just above CON2
(see Fig.6).
Next, download and install the
Windows programming software. The
Parts List – AVR ISP Serial Programmer
1 PC board coded 07110021, 78.5mm x 49.5mm
1 82 x 54 x 31mm (L x W x H) plastic instrument case (Jaycar cat HB6015, Altronics H 0205)
1 4MHz crystal (HC49 package, parallel resonant) (X1)
Semiconductors
1 MAX232 RS232 line driver/receiver (IC1)
1 AT90S1200 microcontroller (IC2) programmed with AVR410a.HEX –or1 AT90S2313 microcontroller (IC2) programmed with AVR410b.HEX (see
text)
1 1N5817 or 1N5819 Schottky diode (D1)
Capacitors
1 10µF 16V PC electrolytic
5 1µF 50V monolithic (multilayer) ceramic
1 100nF 50V monolithic (multilayer) ceramic
2 22pF 50V ceramic disc
Resistors (0.25W, 1% metal film)
1 10kΩ
4 100Ω
Connectors & cable
1 10-pin dual-row shrouded (boxed) PC mount header (CON1)
1 10-pin IDC cable mount socket
1 9-pin IDC female ‘D’ connector
1 6-pin 2.54mm pitch single-row PC mount header (CON3)
2 6-way header sockets to suit CON3
1.5m 10-way IDC cable (for serial cable)
250mm 6-core data cable or 6-way rainbow cable (for ISP cable)
50mm (approx.) 0.71mm tinned copper wire (for links)
Additional parts for 10-way ISP cable (optional, see text)
1 10-pin dual-row shrouded (boxed) PC mount header (CON2)
2 10-pin IDC cable mount sockets
250mm 10-way IDC cable
Additional parts for bootstrap programming (not required if IC2 is
supplied pre-programmed)
1 6-way header socket to suit CON3
1 25-pin male ‘D’ connector
1 2-pin 2.54mm pitch single-row PC mount header (JP1)
1 jumper shunt (for JP1)
450mm 6-core data cable or rainbow cable
Fig.9: you only need to make this cable
if your micro’s (IC2) Flash memory is
“blank”. Bootstrap programming is a
once-only job, so your work doesn’t
have to look too pretty
www.siliconchip.com.au
software we’ve selected is called “PonyProg”, and it’s
available free from www.lancos.com PonyProg runs on
Windows 95, 98, ME, NT4 and 2000 and requires only
minimal hardware.
After installation, power down your PC and connect
the bootstrap programming cable. One end connects to
CON3 on the programmer and the other to your PC’s
parallel port. Install a shorting link on JP1 and hook up
the external 5V DC power source (watch the polarity).
Hold your breath and switch on.
Now power up your PC and launch PonyProg. You’ll
see messages to the effect that “setup” and “calibration”
need to be run before proceeding, so let’s do that first.
The following functions are all accessible from the
menu bar at the top of the main window. First, select
Setup -> Interface Setup. In the window that appears,
choose the “Parallel” option. In the drop-down list,
October 2002 77
Fig.10 (left): PonyProg
can be configured in
just a few seconds.
Our “bootstrap”
programmer is
compatible with
Atmel’s STK200/300
parallel port
programmer, identified
here as an “AVR ISP”.
Don’t check (tick) any
of the “Invert” boxes!
Fig.11 (right): this
is what you should
see after successfully
loading the program
(.HEX) file.
choose “AVR ISP API” if you’re
running Windows 95, 98 or ME,
or “AVR ISP I/O” if you’re running
Windows NT4 or 2000 (see Fig.10).
Click on the OK button to close the
window.
Next, select Setup -> Calibration.
Follow the displayed instructions to
run the calibration. To complete the
basic settings, select Device -> AVR
Micro and choose your micro from the
long list of supported devices.
Before “burning” the micro, you
need to load the program code. Select
File -> Open Program (FLASH) File.
From the “Files of type:” drop-down
list, change “*.e2p” to “*.hex”. Next,
navigate to wherever you unzipped
AVR910a.ZIP (or AVR910b.ZIP, see
above) and double-click on the appropriate .HEX file. The .HEX file
is loaded and displayed in the edit
window (see Fig.11).
OK, it’s programming time.
Select Command - > Write Program
(FLASH) and the Status window
appears. If all goes well, you’ll get a
“Write successful!” message. If you
get an error message instead, use the
Command -> Erase function and try
again.
Once you’ve managed to successfully program the micro, close PonyProg,
power down your PC and disconnect
the programming cable. Switch
off the 5V power source and
remove the associated hook-up
wire, as well as the shorting
link on JP1. All done!
done with sidecutters or a sharp knife
(mind the pinkies!).
The PC board should now slide all
(or most) of the way into the case. As
the board nears the bottom, it should
“wedge” in place, held firmly by the
sides of the case. For a more permanent
installation, you can attach the board
to the bottom of the case using 6mm
stand-offs, 10mm M2.5 screws and
M2.5 nuts.
For ribbon cable exits, file small flat
slots in the lip of the case so that the
cables just fit when the lid is closed.
If you’ve used data cable for the
6-way ISP cable, file an appropriately
sized slot in the lip on one end, or alternatively, drill a hole and fit a grommet.
Using the programmer
The AVR ISP Programmer integrates
with Atmel’s AVR Studio as well as a
number of other commercial development packages.
AVR Studio can be downloaded free
of charge at ftp://www.atmel.com/pub/
atmel/astudio3.exe
No special configuration is required
to get your programmer working with
AVR Studio. Simply connect the
RS232 cable to a free COM port (COM1
Housing
A little surgery is required
in order to fit the completed
assembly in the specified case.
Cut away the integral card
guides of the case so that you’re
left with reasonably smooth
internal surfaces. This can be
78 Silicon Chip
Fig.13: same-size PC board artwork.
Fig.12: AVRprog is invoked
within AVR Studio by holding
down ‘Alt’ and hitting ‘9’.
to COM4 is supported), connect the
ISP cable to the target board and apply
power. To activate the programmer
from within AVR Studio, hold down
the ‘Alt’ key and press ‘9’. The “AVRprog” window should appear, (see
Fig.12).
A stand-alone version of the programming software is also available.
Download it at ftp://www.atmel.com/
pub/atmel/aprogwin.exe
Die-hard DOS fans can download a DOS version from
ftp://www.atmel.com/pub/atmel/aprogdos.exe
Want to know more?
Atmel’s application note
titled “AVR910: In-System Programming” should be consulted
first. You’ll find it on Atmel’s
web site at www.atmel.com
For details on programming
specific microcontroller types,
refer to the data sheets, available
from the Atmel site.
SC
www.siliconchip.com.au
|