Burning the Arduino BT booloader

(with AVR Studio and an AVR-ISP mkII) by djmatic

August 2007 Note: The Arduino 0009 software now includes the ability to burn the bootloader from the Arduino software, using an AVR-ISP MKII. That means you probably won't need the AVRStudio instructions below. If someone wants to try that, and copy the relevant details to a new tutorial, that would be great!

Before you start:

1. Install AVRStudio 4 on a PC.

On a new Mac, you can also use Parallels Build 3150 or later with Windows XP.

2. Connect AVRISP mkII

Burning:

3. Upload the following code to the Arduino, via the Arduino IDE and Bluetooth.

(In the rare case that you have misprogrammed the BlueGiga and lost BT functionality, skip down to #4 and program the code that follows as a hex file. Once that is done, reset and follow the instructions to burn the bootloader itself, starting at #4 again. )

This code needs to be run once to configure the BlueGiga module. Upload it, turn the power off on the Arduino BT board, wait ten seconds and then go on to #4.

/* Arduino BT Configuration File  Feb 05 2007
* ------------------
* Upload and run this file <<once>> to configure the name or other variables of your BT module.
* Don't forget to reset your module so that the new commands are executed.
* ------------------
* Massimo Banzi
*/



int LED = 13;                                     // select the pin for the LED
int RESET = 7;                                    // BT module uses pin 7 for reset

void setup() {
  pinMode(LED,OUTPUT);                            // declare the LED and BT RESET pins as output
  pinMode(RESET,OUTPUT);  

  Serial.begin(115200);                           // connect to the serial port

  digitalWrite(RESET, HIGH);  
  delay(10);
  digitalWrite(RESET, LOW);
  delay(2000);

                                                   // the following "SET BT" commands are one-time commands 
                                                   // that only need to be uploaded to your BT module and run 
                                                   // when you want to change the BlueGiga's configuration.

                                                   // ok. First, the easy to change configuration commands:

    Serial.println("SET BT NAME Arduino_BT");      // you can change the name of your module here. 
                                                   // No spaces allowed in the name; names can be up to 256 charcters.
//  Serial.println("SET BT NAME KarlMarx");        // example


    Serial.println("SET BT AUTH * 12345");         // 12345 == 0 to 16 digit Bluetooth passkey/PIN code

//  Serial.println("SET BT AUTH * 987654321");     // example


                                                   // And now the tricky configuration commands. 
                                                   // Change these only if you know what you're doing. 
                                                   // See the IWRAP manual for details.

  Serial.println("SET CONTROL BAUD 115200,8n1");   // set the BT module serial rate to 115200. Don't change this.

  Serial.println("SET BT PAGEMODE 3 2000 1");      // 3 == IWRAP visible and answers
                                                   // 2000 == 5120ms timeout
                                                   // 1 == iWRAP is connectable every 1.28 sec

  Serial.println("SET BT ROLE 0 f 7d00");          // 0 == allows master-slave switch when calling; 
                                                   // f == enable sniff, park, hold and role switch modes; 
                                                   // 7d00 == keep connection  alive 20 seconds

  Serial.println("SET CONTROL ECHO 0");            // don't echo back module commands

  Serial.println("SET CONTROL ESCAPE - 00 1");     // - == character to escape from comand mode to data mode; 
                                                   // 00 == DTR bitmask; 1 == return to command mode when DTR dropped


}

                                                   // and now a few blinks of the  LED, 
                                                   // so that we know the program is running.

void loop () {                                    
  digitalWrite(LED, HIGH);
  delay(100);
  digitalWrite(LED, LOW);
  Serial.println("ciao");
  delay(1000);
}


4. Start AVR studio and 'connect' the programmer in the software.

5. Connect the AVRISP mkII to the ISP header on the BT module. The light on the programmer will change from red (error) to green (happy). The software will tell you if the cable is in the wrong position.

6. On the "Program" panel of the software, select the device as Amega168.

7. On the "Program" panel of the software, select "input hex file" in the flash section. Choose your hex bootloader file.

8. Click the "Fuses" panel of the software. It will read the exisiting fuses form the chip tio be programmed. Check to see that they are 0xF8 (lfuse), 0xDF (hfuse) and 0xFF (efuse).

9. Click the "LockBits" panel of the software. Check that the lockbits are 0xCF.

10. On the "Board" panel, set and write the ISP frequency. If you are programming the schip for the first time, choose 125Khz. after that (who knows why?) you can set it at 2Mhz.

11. On the Auto panel, select the following:

  • ERASE CHIP

  • Program FLASH
  • Verify FLASH

  • Program Fuses
  • Verify Fuses

  • Program lock bits
  • Verify lock bits

Hit "Start" to program. It should be automatic from there. To program another, just connect it to the programmer, and hit 'Auto'

When you reopen the program the next time, it should remember many of these values.

IMPORTANT:Once you have the correct settings, do not move back and forth from the program panel to the lockbits or fuses panel! Every time you click the LB or fuses panel, the software reads in the chip's setting, and erases whatever you had chosen. If you do look at the LB or fuses panel, you have to make sure you have the correct settings in them before moving to another panel. Just another example of fine user interface engineering. But hey, who complaining with free software?

Share