Time to BURN!
In the previous tutorial, we learned how to build a 'stand-alone' Arduino circuit on a breadboard using an ATMEGA328P microcontroller and some supporting components. That's all fine and good, but we need the ability to upload programs to the bare microprocessor for it to actually be useful.
This can be done in a few ways:
- Program the ATMEGA in the Arduino and pull the chip - (Not very convenient)
- Buy an AVR programmer - ($$$$$)
- Use the Arduino Board as a programmer
In this tutorial we are going to go with the last option and use the Arduino board that is conveniently sitting right in front of you as an ISP.
Once again, a Video is worth a thousand words:
What is an ISP?
ISP stands for 'In System Programmer'. This is a device that lets you upload code into a Microcontroller without removing it from the circuit. There are several types of ISP's ranging from inexpensive home-built circuits to expensive stand alone field programmers that don't even need a computer.
What is the SPI?
SPI stands for 'Serial Peripheral Interface' Bus. This is a communication standard introduced by Motorolla as a way to transfer data between digital devices. We will use this to connect the Arduino board to our breadboard microcontroller.
You can read all the gory details about the SPI here, but this is the minimum you should know. SPI works by categorizing devices as Masters or Slaves. A Master device can be connected to multiple Slave devices. The master also decides which slave to talk to and is in charge of starting communication.
An SPI connection requires four wires:
SCLK - 'Serial Clock' - This is the clock signal that synchronizes the two devices.
MOSI - 'Master Output, Slave Input' - The data line from the Master
MISO - 'Master Input, Slave Output' - The return data line from the Slave to the Master
SS - 'Slave Select" - This line is used to determine which Slave device is listening
To Bootload or not to Bootload?
Whenever you upload a sketch to an Arduino, you are using the Bootloader. The Arduino Bootloader is a small program that permanently lives on the Arduinos' microcontroller. It allows the Arduino to communicate with your computer and download programs.
Since we are using the SPI interface to program the chip, we don't need the Bootloader. In fact, as soon as we upload our first program over the SPI, the Bootloader will be overwritten.
Even though we don't need the Bootloader anymore, It does have one useful trick. Each AVR microcontroller (inluding our ATMEGA328P) has a small chunk of permanent memory called 'Fuses' that control how the chip will behave. These Fuses need to be set in a specific configuration to make the chip Arduino compatible. When you buy a brand new ATMEGA chip from your favorite electronics store, they may not be set correctly.
When you 'Burn the Bootloader' to a chip, part of the process includes setting the Fuses. It is a dead simple way to configure a new chip. (See video for details)
You should now be comfortable using the ATMEGA328P chip in a stand alone circuit and can finally let your Arduino board move on to the next project.