Installing an Arduino Bootloader

Pages
Contributors: M-Short
Favorited Favorite 25

Uploading Code - Hard Way

The hard way is for those people who want to use the command line. This method may be more preferable if you are modifying and recompiling and don't want to have to keep updating the IDE, but otherwise it's pretty unnecessary. Again, you will need to get the programmer and hook everything up. In this example, we are using avrdude on Windows.

There are three steps to this process:

  • Set Fuse Bits (i.e. Low, High, and Extended)
  • Flash .hex File
  • Set Lock Bits

The first step involves setting the fusebits. Fusebits are the part of the AVR chip that determine things like whether you are using an external crystal or whether you want brown out detection. The commands listed below are specifically for the Arduino Uno using an ATMega328, they will probably work on some other similar boards such as the Duemilanove, but make sure you know what you are doing before playing with fusebits. All the required fuse bits are listed in the boards.txt file for different boards. Again, if you have a boards.txt file installed then just use the Easy Way. The second step is actually uploading the program. The final step is setting the lock bits.

Pocket AVR Programmer

Fuse Bits

If you are using the AVR Pocket Programmer to program your target Arduino Uno, type the following commands in the command line to set the fuse bits.

language:bash
avrdude -b 19200 -c usbtiny -p m328p -v -e -U efuse:w:0x05:m -U hfuse:w:0xD6:m -U lfuse:w:0xFF:m

Hex File and Lock Bits

Once the fuse bits are set, we can flash a compiled .hex file to the target board and set the lock bits. Enter the following in a command line. Make sure that you are in same directory as your .hex file and adjust the ...hexfilename.hex that you are using to flash for your target. To flash the Arduino Uno Bootloader, head over to the Arduino program folder. On a Windows OS, it will look similar to this path ...\arduino-1.8.5\hardware\arduino\avr\bootloaders\optiboot. There area few files in the folder but the one we are interested in is the optiboot_atmega328.hex file.

language:bash
avrdude -b 19200 -c usbtiny -p m328p -v -e -U flash:w:hexfilename.hex -U lock:w:0x0F:m

Arduino as ISP

Fuse Bits

If you are using the Arduino as ISP to program your target Arduino Uno, type the following commands in the command line to set the fuse bits.

language:bash
avrdude -P comport -b 19200 -c avrisp -p m328p -v -e -U efuse:w:0x05:m -U hfuse:w:0xD6:m -U lfuse:w:0xFF:m

Hex File and Lock Bits

Once the fuse bits are set, we can flash a compiled .hex file to the target board and set the lock bits. Enter the following in a command line. Make sure that you are in same directory as your .hex file and adjust the ...hexfilename.hex that you are using to flash for your target. To flash the Arduino Uno Bootloader, head over to the Arduino program folder. On a Windows OS, it will look similar to this path ...\arduino-1.8.5\hardware\arduino\avr\bootloaders\optiboot. There area few files in the folder but the one we are interested in is the optiboot_atmega328.hex file.

language:bash
avrdude -P comport -b 19200 -c avrisp -p m328p -v -e -U flash:w:hexfilename.hex -U lock:w:0x0F:m

One last bit of info. As we stated earlier, a bootloader is essintially a .hex file. Thus, you can use this method to upload and code you wish to your ICs.