The basic part of the bootloader is KAVR (http://sourceforge.net/projects/kavr/files/)

It have been slightly changed to fit ATMEGA88PA or ATMEGA328P and then improved to meet blueController needs. Bootsize should be set to 512 words and CPU clock to 8MHz.

 

How does it work?

The iKAVR checks after each reset (button RST) if the button INT0 (PD2=L) is pressed.
If yes, the iKAVR goes for 30s. into bootloader mode and signalize it with fast blinking of PB6 LED.
When data is written to flash the led flashes. After writing the iKAVR starts Application.
The advantage of iKAVR is that it will be only started if needed.
If button INT0 (PD2) is not pressed the iKAVR starts the application immediately, so that the RST button
have normal reset function.

The basic KAVR waits after reset for certain period to get data and program AVR.
The disadvantage of basic KAVR is that you will have to wait for timeout after each reset.

 

Following versions are available:

iKAVR-BTM-328P this is the improved version of KAVR bootloader for ATMEGA328PA

iKAVR-BTM-88PA this is the improved version of KAVR bootloader for ATMEGA88PA

KAVR-BTM-328P_3s this is the basic version of KAVR bootloader, with 3s. timeout after reset

KAVR-BTM-88PA_3s this is the basic version of KAVR bootloader, with 3s. timeout after reset

KAVR-BTM-328P_14s this is the basic version of KAVR bootloader, with 14s. timeout after reset

 

Download the iKAVR-BTM-88PA.hex file ( .hex for BCA8-BTM-88PA).
Download the iKAVR-BTM-328P.hex file ( .hex for BCA8-BTM-328P).
Download the KAVR-BTM-88PA_3s.hex file ( .hex for BCA8-BTM-88PA with 3s. delay).
Download the KAVR-BTM-328P_3s.hex file ( .hex for BCA8-BTM-328P with 3s. delay).
Download the bootloaders.tar.gz file (source and .hex of KAVR and iKAVR).

 

When you are programming the bootloader by yourself, it is important to set the FUSEBITs as follows in order to get the ATMEGA, BTM-222 and Bootloader to work.
Fusebits:

low fuses=0xe2
high fuses= 0xdc or 0xd4
extended fuses=0xfd

lock bits=0x2F
Which should result with: 
divide clock by 8 Disabled
internal RC Oscillator 8MHz...
Bootsize 512 Words
Select BOOT Vector

SPM is not allowed to write the bootloader section

 

If you are using AVRDUDE you can use following command to program the bootloader:

avrdude -p yourCPU -c yourProgrammer -e -U flash:w:FileName.hex
avrdude -p yourCPU
-c yourProgrammer -U hfuse:w:0xd4:m -U lfuse:w:0xe2:m -U efuse:w:0xfd:m -U lock:w:0x2f:m

 

 

 

Using Bootloader

After setting up the bootloader you should test its functionality by sending sample file over Bluetooth.
Connect your module with PC over Bluetooth as described in SOFTWARE section.

If you are using iKAVR:
Press and hold RST button.
Press and hold INT0 button.
release RST while still holding INT0
release INT0 first when RST is released (1second to be sure)

The PB6 Status LED should start blinking fast.
Now simply send the .HEX file of your application to your COM port
within next 30seconds.
Your application should start after transfer is done.

If you are using basic KAVR:
Restart the AVR.
The KAVR goes immediately to bootloader mode after restart
and waits for timeout.
Now simply send the .HEX file of your application to COM port.
Be sure that transaction starts before timeout!
Your application should start after transfer is done.

 

 

You can use following file for testing:

Download the 88pa-test1.hex file ( .hex for BCA8-BTM-88PA).
Download the 88pa-test2.hex file ( .hex for BCA8-BTM-88PA).
Download the 328p-test1.hex file ( .hex for BCA8--BTM-328P).
Download the 328p-test2.hex file ( .hex for BCA8-BTM-328P).

test1 PB6 Status LED blinks with high luminosity
test2 PB6 Status LED blinks with low luminosity