I have some arduino boards (all of them are the RBBB ones from moderndevice & Jeelabs). But rather than buying the kits with the atmega programmed with the arduino firmware, i just bought the boards and populated them. Then came the part of burning the arduino firmware (bootloader) into the atmega328p. I have an Stk500 Atmel programmer. So i figured how hard can it be. Turns out it is very confusing if not hard.
I guess the most confusing part is figuring out which bootloader to use. The latest and greates is the ‘optiboot’ that is supposed to allow faster upload speeds and occupy less space (about 2kb). So that should give more space for your applications.
So after lots of experimentation and hair-pulling, i have these steps that should get the optiboot bootloader into the arduino using your favorite burner (Stk500 in my case) and software (AVR studio4)
- The chip used is Atmega328p
- You are using a 16mhz crystal or resonator
- Using arduino-0021 or higher
- You are planning on burning the Optiboot (v3 or latest) bootloader
- You are using an ‘unbricked’ chip. Which means that the lower 2 lock bits are ’11’
All the above should give you an arduino ‘UNO’. So here are the steps
- Hook up the Atmega for ISP or Parallel burning operation with your burner (STK500 supports ISP and parallel high voltage programming)
- Confirm your ISP settings or HVP settings. If using ISP, the frequency should be less than 1/4 of the chip’s running frequency.
- Read the signature of the chip and confirm it to be Atmega328p [0x1E 0x95 0x0F]
- Once signature is read, erase the chip. This clears out the flash area and clears out the Fuse and Lock bits
- Read the ‘Lock’ bits. It should read 0xFF. Note that it has also been noted that these bits can be 0x3F. That is because the upper 2 bits do not exists and are treated as ‘1’. Hence the bit combination would be 1111 1111 => 0xFF. !!BIG NOTE!!. On no account try to mess with the lower 2 bits (bits 1 & 0). These bits LB2, LB1 can actually lock out the programming of the Flash and the eeprom memory, ‘bricking’ the chip!!. They are used for production to prevent you from accessing the firmware. They should be left as 11
- Burn the ‘optiboot_atmega328.hex’ downloaded from github. Read back and verify
- Now the lock bits. set them to 0x0F (which means BLB12, BLB11 or lock[5:4] = 00. This will prevent bootloader to be modified by itself using SPM). Burn the lock bits. Read back. They would be 0xCF. That is because the upper 2 bits are always 1.
- Fuse bits settings
- Extended Fuse byte : Only bits [2:0] define the BOD. All others are ‘1’. So if no BOD is needed, this can be 0xFF
- High fuse byte : SPIEN(bit 5) = 0, BOOTRST(bit 0) = 0, BOOTSZ1, BOOTSZ0 (bits 2,1) are 11 which gives 256words for the bootloader. That is 256words * 2 = 512bytes for the bootloader (because the flash memory organization is x16 not x8). That should correctly fit the optiboot bootloader which is 512 bytes!.All other bits are 1 . So the High fuse byte = 0xDE
- Low fuse byte: CKDIV8(bit 7) = 1, For ceramic resonator SUT[1:0] = 01 and CKSEL[3:0] = 0110. All other bits are 1. So Low fuse = 0xD6
- So your fuse settings are 0xFF 0xDE 0xD6. Burn them. Read back and verify
And that is it!!!. You now have the Optiboot bootloader on your Atmega328p. Download the latest Arduino binaries, select the board as ‘Uno’, select the correct COM port and you should be good to go!