This is a continuation of some of my more popular posts on the NK site. I had added this post to the NerdKit library section and since I don’t know if the library will return or not, I want to be sure it remains available.
As of late, I’ve noticed a lot of interest in the programming of the bootloader onto either a new or existing micro-controller. This post is to provide a brief instruction to those venturing into this.
Programming a bootloader on a micro-controller requires additional hardware that was not provided with your NerdKit.
First and foremost, programming a bootloader requires a different type of programmer. While there are other methods to install a bootloader, for this instruction, I am going to focus on the ISP programmer. An ISP (or In System Programmer) is a device that connects to the SPI port of your micro-controller to program it via a serial protocol. There are several of these devices readily available on the internet, or if you are adventurous, you can attempt to build your own from scratch.
Some common ISP programmers include:
- DAPA – Direct Access Parallel Adapter. This is a somewhat outdated homebrew programming method. To use this type of programmer, you MUST have a TRUE parallel port in your computer, not a USB to parallel adapter. The schematic for this can be found several places on the web.
- DASA – Direct Access Serial Adapter. This is the serial variation of the DAPA programmer. It is also a homebrew programmer that requires a TRUE serial port in your computer, not a USB to serial adapter. This schematic too can be found several places on the web.
- USB – ISP Programmer. There are several variations of these available. Many commercial types even some directly from Atmel. Some of these would be the Atmel Dragon, USBASP, AVR MKII, USBTinyISP, etc…
There are others including the popular STK500 dev kit from Atmel, and some other buffered parallel port programmers that can be used. The type you use isn’t terribly important. I currently use a programmer I purchased in kit form on ebay. It has the USBASP firmware on it.
Here is a photo of the programmer I use. You may be able to find one on ebay, or from the designers WEBSITE.
NOTE: If you use purchase one of these programmers, be sure to specify the USBASP firmware. There have been problems with the AVRISP MkII emulator firmware especially in Win Vista and 7. I also have the USBASP Firmware in my programmer and can be of more help if we share common programmer hardware should you have a problem.
Once you have your programmer, you need to keep a couple of things in mind. Some programmers will supply power to your circuit for programming, some require the circuit to have power. The programmer I am using is capable of supplying the power. As a result, I do not use the power regulator or battery when programming.
OK, let’s get started.
To program the bootloader you will need to build your breadboard very similar to how the initial setup in the guide describes. If your programmer supplies power, you can leave the regulator portion off the board. The main difference is that you MUST replace the jumper wire at pin1 with a resistor (I use 10k).
Note: If you use the programmer I have, the programmer will supply power if the 5v/3.3v jumper is installed. If you use your own power, you MUST remove that jumper.
This Photo illustrates the basic setup.
Here I have added a small circuit board I made that breaks out the MOSI, MISO, SCK, and Reset pins from the programming cable to my breadboard. You can purchase similar breakout boards on e-bay, or just attach wires into the ribbon cable connector to the proper places on your breadboard.
This photo shows the connections to the micro-controller.
If you go your own route, the pin-out for the connector is this.
This is the header pinout on a board.
And this would be the view of the 10 pin female connector on the cable itself.
Once all your connections are made, you are ready to start loading the bootloader.
If you are using the USBASP like I have, you will need to have the low speed jumper installed when programming the bootloader. This is especially important when installing to a new chip.
The NK team kindly has done most all of the work here for you in providing you with a compiled source to upload and a list of all the fuse settings. The main thing here is to make sure to use the proper bootloader for the chip you are programming. The ATMEGA168 and ATMEGA328P are different and used different fuse settings and bootloader file.
The chip I am using in my example is the ATMEGA328P.
In your code folder you downloaded from the member area, you will find 2 folders for bootloaders. They are called “bootloader168” and bootloader328P)
The first thing you need to do is look at the makefile.
The default makefile uses a DAPA programmer. You must change this to the type of programmer you have prior to attempting to load the files.
In my case, I changed the dapa in the 1st line to usbasp so mine reads like this.
Now, just to make sure we start of fresh, it’s a good idea to do a chip erase. This will make sure the lock bits are cleared and any existing bootloader/program is cleared off the chip. (It will also test the setup.
To do this simply type this from your command line.
(substitute your programmer and micro in the proper spots as needed)
If your setup is good, you should see this response.
If you did, your setup is good, and you are ready to proceed to programming.
After you’ve done the erase, you need to set the fuse bits in the micro to configure it.
This is done by navigating into your bootloader folder and typeing:
If this was successful, you should see a bunch of lines scroll on your screen as each fuse is programmed. Make sure each section verifies. For the 328P I’m programming, this is what the response is from make.
After this is done, you are ready to send the bootloader to the chip. This can be done by typeing:
Once you’ve done this, you should get the following response from make.
If you made it to this point,
You just installed your bootloader. You should now be able to connect the micro-controller as shown in your guide and use it to upload your programs via the NK programming cable.