Configuration and code upload - sambthompson/SAAB-CDC GitHub Wiki

Once your module board is assembled, but before you install it in your Saab, it needs to be configured and the software installed. There are three main steps:

  1. Install a bootloader to the ATMEGA328 via the ISP header. All surface mount units require this after the board is assembled, but the bootloader software is not specific to BlueSaab and is available with the suggested bootloader tools. This step should only need to be done once per assembled board;
  2. Configure the RN52 module with the correct settings, including Bluetooth profiles, discoverability, etc, via the UPLOAD socket or FTDI header. This uses a pass through program developed by Karlis to allow you to talk to the RN52 module from your computer's connection to the ATMEGA328. This should only be required once. A future release of the SAAB-CDC software will avoid the need for this step.
  3. Load the SAAB-CDC software to the ATMEGA328 via the UPLOAD socket or FTDI header. This also in Karlis' GitHub repository (or via .zip release on the forum). This step is needed on initial assembly, as well as when a new release is made available.

Both the second and third steps rely on development tools such as Arduino IDE or Xcode to upload code to the Arduino via the UPLOAD USB socket. FIXME: Need to explain these steps/tools in new section below

Installing the bootloader

Before you can use the FTDI or USB interfaces to communicate with the ATMEGA328, a small piece of support code must be written to the ATMEGA328's on-chip flash memory that then provides support for the FTDI protocol. There are two options:

  1. If you have one lying around, you can use another Arduino board (Uno, Nano, etc) as the ISP programmer; FIXME: Does it need to be 3.3V?
  2. You can use a dedicated ISP module.

Arduino as ISP

Arduino boards can act as In-system Programmers in order to load bootloader software to other boards. In this case the ICSP header (if available) or the GPIOs on the Arduino board connect to pins on the BlueSaab.

Connecting the PC to the BlueSaab via Arduino

Connect the Arduino to your PC via the Arduino's USB port.

The exact connections between the Arduino and the BlueSaab ISP1 port depend on the module of Arduino available. See the following links for details.

FIXME: Add links for various Arduino models

Bootloader upload software tools for Arduino as ISP

There are two tools that can be used to support this:

  1. The Arduino IDE;
  2. AVR Downloader/Uploader (AVRDUDE) CLI tool;

Using the Arduino IDE

Select "Arduino as ISP"

Using AVRDUDE

See this tutorial.

FIXME: Don't know how this works. Needs research.

AVR-ISP

This is a dedicated USB to ISP interface, for example the AVR ISP MkII.

Connecting the PC to the BlueSaab via dedicated ISP interface

Plug the 6 pin connector onto the ISP1 header and the ISP module's USB cable into your computer. Note: make sure the plug's pin 1 matches the BlueSaab board's pin1. There is no physical barrier to plugging in the wrong way around!

Bootloader upload software tools for ISP modules

There are two tools that can be used to support this:

  1. The Arduino IDE;
  2. AVRDUDE;

Using the Arduino IDE

Select "AVR-ISP MkII"

Using AVRDUDE

FIXME: Don't know how this works. Needs research.

RN52 Configuration

The steps needed to correctly configure the RN52 module depend setting the communication speed between the ATMEGA328 and RN52 module to 9600 bits per second (BPS). This in turn can be forced by the hardware configuration of your board, in particular whether or not the GPIO7 pin on the module is tied to ground. If:

When entering commands, the characters you type will not be echoed back to you, but when you hit enter, unless otherwise noted in the instructions below, the RN52 will respond with one of the following strings and meanings:

  • AOK: your command was accepted and was executed successfully;
  • ERR: your command was accepted but was not executed;
  • ?: your command was not understood by the RN52.

If you get a response back other than AOK, you can try re-entering the command, to ensure it was correct. If it's still rejected, you can try returning to the beginning of the factory reset process, and see if that helps.

Factory Reset

  1. Connect BlueSaab module to your computer using USB->FTDI cable or connect to UPLOAD socket.

  2. Open 'RN52-BT-PRG' code and make sure that BAUDRATE constant in 'RN52.h' file is set to 9600.

  3. Upload the code to BlueSaab module.

  4. Open Terminal app of your choice using baud rate @ 9600bps. You should see the following output:

    RN52 programming mode
    CMD
    
  5. Enter SF,1 command. This will instruct the RN52 to reset to factory defaults.

At this point, if the GPIO7 pin is grounded, you'll be able to skip the next section and proceed to the following section, since these are designed to reset the bit rate to 9600 after a factory reset to the default of 115200, but the grounded GPIO7 pin prevents this change. Otherwise proceed to the next section and follow all the remaining steps in order.

Reset bit rate to 9600

  1. Disconnect the module from your computer.

  2. Edit 'RN52.h' file and change the constant BAUDRATE to 115200.

  3. Connect BlueSaab module back to the computer and upload the code.

  4. Open Terminal app of your choice and make sure that you now use baud rate @ 115200bps.

  5. Enter SU,01 command. This will instruct RN52 to switch the comms to 9600bps.

  6. Disconnect the module from your computer.

  7. Edit ‘RN52.h’ file and change the constant BAUDRATE to 9600.

  8. Connect BlueSaab module back to the computer and upload the code.

  9. Open Terminal app of your choice using baud rate @ 9600bps. You should see the following output:

    RN52 programming mode
    CMD
    

Now proceed to the next section to complete the settings.

Complete the settings

  1. If you skipped the reset section above, restart the RN52 module by entering R,1 command. This will ensure the RN52 module is operating with the factory settings.
  2. Enter S-,<whatever> command. This will set the modules ‘normalized’ name to <whatever>-, followed by last four symbols of the MAC address. This is not visible to the end user.
  3. Enter SN,<whatever> command. This will set the modules ‘broadcast’ name to <whatever>. This is what you will see in the Bluetooth settings of your audio source (phone, tablet, etc.).
  4. Enter SC,200420 command. This will set ‘CoD’ (class of device) to “car audio”.
  5. Enter SS,0F command. This will set the volume gain on the module to max (value 15).
  6. Enter S%,0084 command. This sets the following extended features to “ON”:
  • Discoverable on startup
  • Disable system tones
  1. Enter SD,06 command. Sets the discovery mask to A2DP and SPP protocols.

  2. Enter SK,06 command. Sets the connection mask to A2DP and SPP protocols.

  3. Reboot the module again with the R,1 command.

  4. Disconnect the module from your computer.

  5. Connect BlueSaab module back to the computer and open Terminal app of your choice using baud rate @ 9600bps. You should see the following output:

    RN52 programming mode
    CMD
    
  6. Enter D command. This will list all the current RN52 settings. Verify that they are the same as you programmed earlier.

    *** Settings ***
    BTA=00066652055C
    BTName=<whatever>
    Authen=2
    COD=200420
    DiscoveryMask=06
    ConnectionMask=06
    PinCod=1234
    AudioRoute=00
    ExtFeatures=84
    
  7. Close terminal connection.

Your BlueSaab's RN52 module is now ready for CDC software upload.

CDC software upload

  1. Locate the latest release of the BlueSaab CDC software and download. See this forum for release announcements.
  2. If not already connected, connect BlueSaab module to your computer using USB->FTDI cable or connect to UPLOAD socket.
  3. Open 'SAAB-CDC' code.
  4. Upload the code to BlueSaab module.

After this process, the Power light should be on and the BT LEDs should be flashing alternately, meaning the module is discoverable. You can try pairing it to your device to see if that works.

After upload, disconnect the BlueSaab module from your PC.

⚠️ **GitHub.com Fallback** ⚠️