Thursday, September 12, 2013

The trick to get the BLE112 working

The BLE112 Bluetooth module is a v4.0 bluetooth module from Bluegiga and is marketed as low energy and programmable. It is based on the CC2540 Bluetooth chip from Texas Instruments - note the CC in the part number stands for ChipCon which is a Norwegian RF company taken over by TI.

OverView
The original Bluegiga modules such as the WT12, WT11 and long-range WT41 (referred to as "Classic") are super easy to use. Just enter SET with a carriage return into the Serial port and the the Settings are sent out the Serial port. The new BLE112 is not so easy to use and is not backwards compatible with the classic modules. For a start there are four Serial ports and none of them will do anything until the module is programmed. And to program the module requires an external programmer and a lot of knowledge about blueguga script (bgs) what each xml file does. The aim here is to go through what is required, and shortcut a very steep learning curve. The information below took around 3 months and around 50 emails to the Bluegiga contact. While the BLE112 is difficult to get used to, it is the future of bluetooth communications.

QuickStart Guide
To get started on the BLE112, the best way is to purchase a USB-BLE112 adaptor. Here are the options:
  • Purchase two USB-BLE112 USB adaptors - programmed with EV_MASTER and EV_SLAVE
  • Purchase a USB-BLE112 USB adaptor and a BLED112 USB dongle.
  • Purchase one USB-BLE112 USB adaptor and connect to a computer or mobile device
With the USB-BLE112 USB adaptor, this can be plugged straight into a USB port, the FTDI driver installed, the BlueTerminal program installed and run, and the reset button can be pressed on the side to view the reset message. When a bleutooth connection is made (this is automatic with the example firmware), simply type data in and it will come out on the other bluetooth device.


How to Program
The BLE112 module can be programmed with a CC Debugger available from E-14 or TI direct for around $50. If you are serious about the BLE112, do this first. The CC-Debugger plugs into the USB Port and has a ten pin IDC interface for programming the BLE112. On the USB-BLE112, there is not enough room for a connector so we have placed an IDC10 connector footprint which the CC-Debugger can be plugged into. To improve contact, the connector can be twisted gently and when the green light is on, the USB-BLE112 module is ready to program.


How to Compile
The Bluegiga documentation is very extensive on the BLE112 but is dry and lacks examples. The best way to learn how to program is to download the example projects, compile and download them and then modify.

EDIT: The bluegiga website has been upgraded so the links below have moved. 

To compile, go to Bluegiga Support, login (or register), click on the BLE112 picture, select Software Releases and download Bluetooth Smart v1.1.1 (refer to picture above)  and then download the BLE Update program available by scrolling down to PC Utilities (refer to picture below) - it is called the Bluetooth Smart firmware update tool.


Now download, the four sample projects, EV_MASTER, EV_SLAVE, D_MASTER and D_SLAVE. EV stands for Evaluation kit and this software should be programmed into the USB-BLE112 while D stands for dongle or the BLED112. Double clicking on the .bgproj file will now open the BLE Update program. If no .bgproj file is available, just copy the project.xml file and add a .bgproj suffix. Please note that the first time this is used, a licence key will be needed. This can take up to 24 hours for Bluegiga to reply.

With the BLED112 dongle, this can be programmed using the DFU program. Below are the contents of a batch file and the out.hex file should be taken from D_MASTER directory.
..\..\bin\dfutool.exe 2458:fffe out.hex

The Firmware
The firmware is in the .bgs or bluegiga script file. Bluegiga recommends Notepad++ as the editor and there is a Bluegiga extension for Notepad++. Below is the first part of the firmware which shows the initial routine (or the setup() routine for Arduino users). The endpoint is the port which the data uses to trasnkit & receive. System_enpoint_uart1 is equal to 5 and is the second serial port with the other serial ports being uart0, uarts 2 and uart3. call system_endpoint_tx is the same as a puts command and the second argument 63 is number of characters in the string. Hopefully later on Bluegiga will remove this but one way to find this otu is to compile and the compiler will advise what this argument should be.

event system_boot(major, minor, patch, build, ll_version, protocol_version, hw)
 
    endpoint = system_endpoint_uart1
 

    call system_endpoint_tx(endpoint, 63, "\n\r** Boot: Connection Slave, GATT Server ** Version: et-0.8 **\n")

Good Luck and may all your Bluetooth connections be successful.

Youtube video showing the BLE112 in action
http://youtu.be/8abV9guO654

References
Programming BLE112
Jeff Rowberg's BLE112 page on Inmojo