This is only a preview of the October 2001 issue of Silicon Chip. You can view 30 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. Items relevant to "Build Your Own MP3 Jukebox; Pt.2":
Items relevant to "Super-Sensitive Body Detector":
Items relevant to "An Automotive Thermometer":
Items relevant to "Programming Adapter For Atmel Microcontrollers":
|
The adapter can program virtually any Atmel
microcontroller in-circuit. It’s shown here
ready to program the microcontroller in the
“IR Remote Receiver & Display” unit described
last month.
In-System Programming
Adapter for Atmel
AVR Microcontrollers
If you’re interested in experimenting
with microcontrollers but aren’t keen on
spending big dollars on a “starter” kit, then
this project is just what you’ve been looking
for. Together with a Windows-based PC
and some free software, it will allow you to
program most Atmel AVR microcontrollers
right in-circuit!
I
By PETER SMITH
F YOU BUILT the “IR Remote
Receiver & Display” described last
month, this project will allow you
to program the microcontroller chip
yourself. In fact, that’s why we developed this simple circuit but it can also
be used for programming almost any
Atmel AVR microcontroller in-circuit.
Basically, the device is a simple
68 Silicon Chip
adapter that sits between the parallel
port of your PC and the device to be
programmed.
It’s alive!
If you’re new to microcontrollers,
you’re probably wondering what all
the fuss is about. Why do they need
to be “programmed”?
Microcontrollers are essentially
microcomputers with built-in program memory, as well as other useful
interface logic. When you buy one of
these little devices from your local
electronics outlet, its memory is blank.
That is to say, it has no instructions
“telling” it what to do.
Before it can be used in project
“X”, its memory must be programmed
before it will perform as the project
designer intended.
So grab your blank micro and let’s
head off to the lab for a memory implant …
In days of old…
Once upon a time, end-user-programmable microcontroller memory
was EPROM-based. Like the traditional UV-erasable EPROM memory
most readers would be familiar with,
it’s programmed in a parallel fashion
(one byte at a time) using high voltages.
www.siliconchip.com.au
But that’s all in the past. Flash
memory technology now allows fast
electrical erasing and programming
at normal chip supply voltage levels.
Add to that a “smart” serial interface
and programming the current crop of
microcontrollers becomes an almost
trivial task.
Atmel’s Solution
Atmel microcontrollers incorporate a serial programming interface
(SPI) that is designed specifically for
in-system programming (ISP). Three
I/O port pins do double-duty as control
and data pins for the SPI. These are
the serial input (MOSI), serial output
(MISO), and serial clock (SCK) pins.
Programming is achieved by holding
the reset (RST) pin low continuously
from power-on, then sending the
appropriate commands and data to
the serial input (MOSI) pin. Memory contents can be read out via the
serial output (MISO) pin, which also
provides status information. Data is
shifted in and out of the SPI under
control of the serial clock (SCK) pin.
+5V
VDD
CRYSTAL
OR OTHER
CLOCK
SOURCE
3 x 1k
PB7/SCK
XTAL1
PB5
PB5/MOSI
XTAL2
PB7
PB6
PB6/MISO
TO USER
CIRCUITS
SCK
RES
MISO
ATMEL AVR
MICRO
MOSI
RST
GND
+5V
FROM
RESET
CIRCUIT
A
K
OPTIONAL
PROGRAMMING
INDICATOR
1k
TO ISP
HEADER
LED
Fig.1: building in support for in-system programming in your designs
is not difficult. In many cases, all that’s required are three additional
resistors, as shown here.
Connecting to the interface
In order to program one of these
micros, we need to connect some
kind of programming adapter to the
SPI pins. On the AT90S2313 microcontroller (as used in our IR Remote
Receiver & Display project), the SPI
signals appear on the same pins as
the upper Port B input/output (I/O)
signals – PB5, PB6 & PB7. These pins
behave like any other port pins during
normal operation but take on the SPI
functions when programming mode
is entered.
In a typical design, external (user)
circuits will be connected to some or
all of the port pins. How do we prevent
the obvious conflict that will occur
between the user circuits and the SPI
Fig.3: the pinouts recommended by
Atmel for the serial programming
interface. The header is of the
standard 10-pin dual row variety.
www.siliconchip.com.au
Fig.2: designs that need more drive from the micro’s port pins may need a
means of switching between the user circuits and programming interface.
Here we show how this can be achieved using an analog multiplexer – an
idea suggested by Atmel.
signals? One possible solution is to
build in isolation resistors, as shown
in the simplified circuit of Fig.1. This
works well if the I/O pins are used for
inputs only, or if used for outputs, only
need to sink or source a few mA of
current. A universal solution is shown
in Fig.2, where the user circuits are
isolated with an analog multiplexer
when in programming mode (RST
signal low).
Of course, the simplest solution of
all would be to incorporate jumpers
or DIP switches in the design so that
Fig.4: a block diagram of the complete programming system. Power
for the adapter is supplied from the target board.
October 2001 69
adapter (they call it a “dongle”) that
plugs into the parallel port of your PC.
In conjunction with Windows-based
software, it allows programming of
both the data (EEPROM) and program
(FLASH) memory in most of their microcontrollers (see Fig.4).
Atmel supply the programming
dongle with some of their microcontroller development kits. We know you
probably don’t want to buy the whole
kit (!), so we’ve designed an equivalent
adapter based on information freely
available on the Internet.
Our programming adapter
Referring to the circuit diagram in
Fig.5, you can see that all that is required is a buffer (IC1) and a handful
of resistors to provide some signal
conditioning and circuit protection.
In fact, we’ve seen some circuits published that connect the parallel port
lines directly to the microcontroller’s
SPI pins. We don’t recommend that
approach at all, as damage to your
computer, or more likely your microcontroller, is entirely possible.
IC1 incorporates two quad tristate
buffers, with their outputs enabled
under software control by logic “low”
signals on pins 1 and 19. As you can
see, some outputs have been parallelled to increase drive capability. This
is especially important for the reset
(RST) line, which may have a strong
pull-up to +5V on the target board.
Fuse F1 and diode D1 provide basic
reverse-polarity protection. The idea
here is that the diode shorts the +5V
supply to ground and blows the fuse if
you should inadvertently reverse the
power connection to the board.
Note that reversing the ISP cable
won’t blow the fuse but it may damage
IC1. This is much less likely to occur if
you use polarised (shrouded) headers
at both ends, as the header plugs are
keyed to match and will only mate one
way around.
By the way, we placed the fuse
in the ground return instead of the
Fig.5: the circuit uses a single 74HC244 octal buffer (IC1a & IC1b) plus a handful
of resistors. This provides signal conditioning and protects the microcontroller
to be programmed and the PC’s parallel port.
the user circuits can be completely
disconnected from the port pins when
the programming adapter is connected. Trouble is, it’s a real pain having to
continually install and remove jumpers each time you want to program
and test your code (and for me, that’s
lots ‘a’ times!).
You might have noticed that we
haven’t provided any isolation at all
in our IR Remote Receiver and Display
project. Careful port pin assignments
and a little hocus-pocus in the micro-
controller’s code allowed us to keep
the parts count low.
To provide a connection point for
the programming adapter, the SPI
signals are routed to a standard 10pin dual row header, with pinouts
as defined by Atmel (see Fig.3). The
header also provides power to the
programming adapter.
Atmel’s programming adapter
As luck would have it, Atmel has
designed a simple programming
Table 1: Resistor Colour Codes
No.
1
7
1
7
70 Silicon Chip
Value
100kΩ
10kΩ
470Ω
220Ω
4-Band Code (1%)
brown black yellow brown
brown black orange brown
yellow violet brown brown
red red brown brown
5-Band Code (1%)
brown black black orange brown
brown black black red brown
yellow violet black black brown
red red black black brown
www.siliconchip.com.au
Fig.6: follow this parts layout to build the PC board.
Make sure that IC1, LED1 & D1 are installed with the
correct polarity.
Fig.7: the full-size etching pattern for the PC
board. Check your board against this pattern
before installing any of the parts.
power rail in an effort to avoid the
potential meltdown that could occur
under certain circumstances. If the PC
doing the programming is also used to
power the target board and the power
supply is reversed, then +5V is connected directly to the ground return
of the parallel port (can anyone smell
something burning…?).
You may be wondering why we’ve
specified a 250mA fuse when a smaller
current rating would seem to be more
appropriate. Unfortunately, smaller
fuses have significantly higher resistance and would introduce a lot more
“ground noise” into the circuit.
Construction
All parts are mounted on a 70 x
70mm single-side PC board. Referring
to the overlay diagram (Fig.6), begin
by installing the six tinned copper
wire links and all the resistors. Next,
install diode D1, the socket for IC1,
the two capacitors and the fuse clips
for F1.
The two connectors can be installed
next. Make sure that pin 1 of CON2
is aligned as shown on the overlay
diagram; when aligned correctly, the
keyed side of the connector faces
inwards (towards the centre of the
board). Also of note is the mounting
method for CON1, the D-25 connector.
Some variants of these connectors
have solder tails to secure them to
the PC board, whereas others need to
be secured with M3 screws and nuts.
www.siliconchip.com.au
There’s no need to install the
board in a case – just attach
stick-on rubber feet to the
corners to stop it scratching
your desktop.
If you have the type that requires
screws, then be sure to fit the screws
and tighten them up before soldering
any of the pins.
To complete the assembly, install
IC1 and LED1, noting that the shorter
lead of LED1 is the cathode and must
be orientated as shown.
Housing
To keep costs down, we haven’t
specified a case for this project. Sim-
ply stick a small self-adhesive rubber
“foot” in each corner to protect your
desk and prevent the board sliding
around too easily.
Cables
If your PC sits on your desk, then
you might find that you can plug the
adapter directly into the parallel port
connector. Alternatively, you can
make up a suitable cable using one metre of 26-way IDC ribbon cable and two
October 2001 71
Fig.8: the software selects LPT1 by
default. If you have connected to a
secondary port, select it here.
cable-mount 25-way IDC connectors.
Remember that you need to strip one
conductor off the ribbon cable before
attaching the connectors.
You could also use shielded data
cable and solder-type D-25 connectors
for the job. These will be a little cheaper
than the IDC versions, but will take a
lot longer to assemble. We don’t rec-
Parts List
1 PC board, code 07110011,
70mm x 70mm
1 90° PC mount 25-pin male ‘D’
connector (CON1) (Altronics
cat P-3220)
1 10-pin dual row PC-mount
header (shrouded or ‘boxed’
type) (CON 2)
2 10-pin IDC (cable mounting)
header sockets
1 20-pin IC socket (machined pin
type)
1 M205 250mA fast-blow fuse
2 M205 PC-mount fuse clips
1m 10 way IDC ribbon cable
Semiconductors
1 74HC244 octal buffer (IC1)
1 3mm red LED (LED1)
1 1N4001 1A diode (D1)
Capacitors
1 0.47µF 63V MKT polyester
1 220pF 63V MKT polyester
Resistors (0.25W, 5%)
1 100kΩ
1 470Ω
7 10kΩ
7 220Ω
Miscellaneous
4 small self-adhesive rubber feet
10cm (approx.) tinned copper
wire for links
Optional (see text)
1 25-pin IDC male ‘D’ connector
1 25-pin IDC female ‘D’ connector
1m 26-way IDC ribbon cable
72 Silicon Chip
Fig.9: most AVR micros can be
programmed. Choose your chip!
ommend pre-made printer extension
cables be used, as they are generally
too long and may introduce reliability
problems; keep the length down to no
more than about one metre if possible.
For the connection to the target
board, make up a second cable using a
short length (no more than one metre)
of 10-way IDC cable and two 10-way
cable-mount IDC plugs.
Testing
Without the parallel port cable connected or the fuse installed, connect
the ISP cable between the programming
adapter and the board that contains
the microcontroller that you wish to
program (the “target” board). Apply
power to the target board and connect
the positive lead of your multimeter to
the cathode end of D1 and the negative
lead to the righthand fuse clip (the clip
closest to the ISP cable). Your meter
should read +5V.
If all is well, install IC1 and the
fuse, hook up the parallel port cable
and get ready to “burn” your first
microcontroller!
Power-up sequence
We recommend that you connect
both adapter cables before applying
power to the target board and remove
power before disconnecting. This
prevents damage to IC1 and the microcontroller that could be caused by “hot
plugging” power to the adapter.
We’ve included current-limiting re-
sistors on the adapter inputs to protect
IC1 and your PC’s parallel port lines,
so it’s not necessary to power off your
PC when connecting or disconnecting
the adapter. Even so, some readers
have suggested to us that if you intend
controlling home brew devices with
your parallel port, it’s not a bad idea
to purchase a parallel port expansion
card. The idea is that if something goes
wrong, you damage the add-on card
and (probably) not your motherboard.
We agree!
Installing the software
You need a PC running Windows
95 or 98 to use this software. It might
also run on Windows Me but we
haven’t tried it. Unfortunately, it
doesn’t work reliably on Windows
NT4 and the same probably goes for
Windows 2000, no doubt because it
was never intended for these platforms.
If you haven’t already done so,
download the Atmel AVR ISR software from the Atmel ftp site at
ftp://www.atmel.com/pub/atmel/avr_
isp.zip*. If you intend programming
the microcontroller in the IR Remote
Receiver and Display project (as
we’ll do in the following example),
then you’ll also need to download
the program files for this project
from the Silicon Chip website at www.
siliconchip.com.au
Unzip all files in the avr_isp.zip
archive into a temporary directory and
then double-click on the setup.exe file
to launch the installation. Follow the
on-screen prompts to complete the
installation.
Setting up the software
When you run the AVR ISP software,
you will be presented with a large empty window. From the menu bar, click
on Options and choose Change Printer
Port. If your adapter is connected to
LPT1, you should get a display like that
shown in Fig.8. Change the port if nec-
Fig.10: for convenience,
all settings for the session
can be saved in a project
file.
www.siliconchip.com.au
essary, and check that you get a “Dongle
Found” message. If not, there may be a
problem with your adapter of parallel
cable. Click on the OK button to close the
dialog.
Still on the menu bar, click on Project
and select New Project. A dialog box
appears with a list of all supported
microcontrollers (Fig.9). Select the
AT90S2313 and click on the OK button.
Three separate windows then appear,
with the Project Manager window in
front (Fig.10). Enter a title for the project, as well as any comments you like.
Next, click on the Program Memory
window to bring it to the front. Displayed in this window, in hexadecimal
notation, are all the bytes that will be
written to the micro’s FLASH (program)
memory. Notice how all the bytes have
been automatically initialised to FF, the
value of “blank” (erased) memory.
Individual bytes can be edited directly in the memory windows but
thankfully, we don’t need to do that!
To load the code for the IR Remote
Receiver and Display project, click on
File on the main menu bar and choose
Load. A dialog box opens prompting
you to choose the file to load, so navigate to wherever you unzipped the
files for the project and choose the
IRRLCD.HEX file. Now click on the
OK button, and a message will appear
stating that the file was loaded successfully.
For this project, we also need to program the data (EEPROM) memory. Click
on the EEPROM Data Memory window
to bring it to the front. Note that by
default, these windows are cascaded,
but can be moved around for easier
access. Follow the same procedure as
before, but this time load the IRRLCD.
EEP file (Fig.11).
Fig.11: after loading the program and data files, your screen should look
something like this.
message will be displayed. Otherwise,
you’ll hear a “beep” when it’s finished
and see a message flash up so quickly
that you don’t have time to read it. This
indicates success!
Want more information?
Burn baby, burn!
OK – check that everything is hooked
up and power is turned on. Again from
the main menu, click on Program. A
drop-down list appears, giving you
the option of erasing, programming, or
verifying the device (FLASH memory)
or EEPROM memory (see Fig.12).
You could perform each of these operations in turn but there is a quicker
way. Select Auto Program from the list
to have all the steps performed automatically in sequence.
If all is well, a small dialog box with
a progress bar appears (see Fig.13).
Should the Auto Program sequence
fail for any reason, an appropriate error
www.siliconchip.com.au
Before closing AVR ISP, don’t forget
to save your project. Click on Project
and select Save As. Enter a name for the
project, navigate to wherever you want
to save it and click OK. Note that project files should be saved with a .AVR
extension for easy identification later.
Then next time you want to reprogram
the same device, simply select Project,
Open Project to open the project file,
and all your settings, including the
program and data files, will be instantly
reloaded.
Fig.12: functions can be executed
individually, or in automatic
sequence using Auto Program.
If you want to change the way
Auto Program works, check
out the Auto Program Options
selection.
Fig.13: if you get this far, you’re
just seconds away from a
successful implant!
All the technical details on serial
programming are included in the data
sheets for each microcontroller type. Go
to www.atmel.com to download your
copy. While you’re there, check out AVR
Studio, a complete development environment for AVR micros – and it’s free!
Many of our projects also use PIC
microcontrollers from Microchip. Unfortunately, they cannot be programmed
with this adapter. However, the PIC Test
Bed described in our January 2001 issue
includes a simple serial programming
scheme.
*NOTE: the Atmel AVR ISP software
is no longer available. Use Ponyprog
instead. This can be downloaded from
http://www.lancos.com/prog.html —
set it up for the "AVR ISP (STK200/300)
SC
parallel port interface".
October 2001 73
|