the various operations shown.
Enough Theory, Please!
We’ve buried ourselves in a whole bunch of theory,
but theory alone isn’t going to get that LED blinking. I’ve
always been the sort of person who refers to the manual
only when absolutely necessary, but when I first looked at
the cryptic code in Atmel Studio I went straight for the
theory. So, thanks for sticking out the fundamentals. I
hope it has set the scene to get that LED blinking!
Step 1: Get Prepared
The first step to get going is to download and install
your IDE. If you would prefer not to use Atmel Studio,
then you can still go along with these articles; you’ll just
need to find the corresponding menu
commands for compiling and Flashing the
microcontroller. At the level we’re working at,
you should be fine using this code in other
IDEs, preferably using the GCC toolchain.
Atmel Studio (see [ 2] in Resources) is
easy to download and install — just follow the
Step 2: Connect the LED
We’re going to be doing the same thing
as we did in the first article by connecting
our LED. Connect the LED and resistor in
series to PB0 (that’s pin 14) on the
Step 3: Connect the Programmer
In the previous article, we used an FTDI
breakout board to program the
microcontroller with our Arduino sketch. This
month, we’re going to step it up a notch and
use a “real” programmer.
There are two advantages to this. Firstly,
you don’t need a bootloader on your
microcontroller which means you can use microcontrollers
that don’t have bootloaders written for them (the previous
article discussed how bootloaders work).
Secondly, we can program any AVR microcontroller
with a programmer; we can only use an FTDI breakout
board for those with dedicated serial pins (more on serial
later in the series).
I’m sure you’ve seen those six pins labelled ICSP on
your Arduino Uno. They’re there to connect a
programmer. Another choice needs to be made here:
What programmer should I use? I’ve highlighted a few of
the more popular ones in the sidebar, Choose a
Programmer. For now, if you’re looking for a cost-effective
one, I recommend one based on the USBTinyISP or
USBASP. If you want one later that will allow you to
interactively debug your programs, then it’s probably a
42 April 2015
MISO 18 (MISO)
5V Breadboard positive power rail
SCK 19 (SCK)
MOSI 17 (MOSI)
RST 1 (RESET)
GND Breadboard negative power rail
FIGURE 6: Hooking up a programmer
to an ATmega328P microcontroller.
Choosing a Programmer
There are a large number of programmers available for AVR devices — a reflection
of the popularity of AVR microcontrollers amongst hobbyists and enthusiasts. It
would be impossible to highlight them all here, so I've gone for four of the more
Atmel AVRISP mkII In-System Programmer
This is Atmel's own programmer, so is natively supported by Atmel Studio. It, of
course, supports all the AVR ATtiny, ATmega, and ATXmega microcontrollers, so it's
a good choice if you want something that's simple to use and does what it says on
the box. It's pretty cost-effective ($34 at time of print), and is the de facto standard
for programming AVRs (see [ 7] in Resources).
The USBTinyISP is the programmer that I use. The attraction for me was that it was
open source (so you could even build one yourself); it’s available from a number of
manufacturers in different guises (Adafruit sells them as a USBTinyISP kit, and
SparkFun as a complete board called the PocketAVR Programmer); and it comes in
at around $16. The disadvantage is that they aren't supported natively by Atmel
Studio, but we work around that fairly easily in this article (see [ 9] in Resources).
This is a fairly new product from Atmel, and is, in fact, more than a programmer —
it's a debugger too. This means that you can debug code while it's running on your
AVR microcontroller — a very useful thing to be able to do as your projects
increase in complexity. It can program and debug AVR and ARM microcontrollers,
so if you're sticking with Atmel and start working on larger more powerful ARM
processors, it's a good choice. The Basic version comes in at $49, so it’s not out of
reach. As soon as my local supplier gets these in stock, it's on my shopping list (see
[ 8] in Resources).
Arduino as an ISP
You may have come across tutorials explaining how you can use your Arduino Uno
as a programmer for raw microcontrollers. The Arduino team have written a sketch
for upload onto your Arduino Uno, that enables you to program AVR
microcontrollers. This is a great way to start, but does take your Arduino out of
circulation. Additionally, it takes a little time to connect all the correct pins. Halfway
through my first project, I ditched this and spent the $16 to buy the USBTinyISP.