“Everything is Better with Bluetooth”: Add Your Own Custom Bluetooth LE to Your Next ProjectJune 28, 2017 by Mark Hughes
Bluetooth low energy (BLE) is designed to intermittently transmit information using a limited amount of power. This article provides the building blocks that allow you to add BLE to your projects for $5 (plus a one-time purchase of a $15 programmer).
This article uses Code Composer Studio to program a pre-certified module with TI's CC2640F128 Bluetooth System on Chip to function as a simple UART transmitter. This project provides the basis to inexpensively add BluetoothLE to any of your projects.
Bluetooth Low Energy (BLE) was designed for the Internet of Things. This project will provide the steps needed to add BLE to your next project at the module level. By programming a precertified module yourself, you can add Bluetooth to your next project for $5 per module ($25 for 5 modules), or $3.80 when purchasing a batch of 1000. This is a 75% reduction in cost over most hobbyist modules available through Sparkfun or Adafruit. This project uses a JTAG programmer that is available for $15 from Texas Instruments. That means that you are able to program your first five modules for $40, with additional batches of five modules for $25.
This module is based on Texas Instrument's CC2640 SOC. While the steps provided below should allow a user to program any CC26x0 device, the GTTronics carrier board was selected for this project as the least expensive means to program the chip that leaves the user with a precertified device. The next cost improvement happens with design at the component level, however, that would require users to fabricate a circuit board and obtain FCC certification, which would negate any small-scale cost savings.
While I have provided instructions that allow users of all skill levels to be successful with this project, to modify the Bluetooth software past the example project stage, you will need to be an intermediate-level or advanced-level programmer. All parts used in this article were purchased by AllAboutCircuits or are free-of-charge to the general public from the manufacturer.
|CC264BPA Module (5-pack)||Bluetooth LE Module built around TI's CC2640F128||$25 | $25||Datasheet|
|Ti XDS110 DevPack||XDS110 Programmer and Debugger||$15||Webpage|
|CC264BPA-TIEM (optional)||CC264BPA Evaluation Module||$20||User Guide|
|JTAG pitch change converter (optional)||Adafruit 2x5 0.05" pitch to 2x5 0.01" pitch||$2|
|CC264BPA-UDOG (optional)||CC2640 USB HID Dongle||$20||User Guide|
Preparing the Texas Instruments XDS110 DevPack Debug
TI's XDS110 DevPack Programmer is a $15 JTAG Programmer/Debug tool that has a standard 2x5 pin 0.05" pitch female header in the lower left-hand corner for connecting to your microcontroller. Additionally, a 2x10 0.05" set of through-hole test points at the top of the board provide additional functionality. If you do not want to provide your own 3.3 V supply for your module, you can solder two wires to holes 1 and 2 at the top of the board to provide a reference ground and a 3.3 VDC supply. Alternatively, run a wire from the 3.3 V supply in the 2x10 test pins to pin 1 of the JTAG connector.
Left: A Pinout Diagram (Pertinent Pins Only) of the Ti XDS Debugger Devpack. Center: An XDS110 Debugger Devpack with wires connected for 3.3V Power and Ground. Right: An optional connection between 3.3V power (pin 1 of the through holes) to pin1 of JTAG debug probe (click image to enlarge).
The CC264BPA-TIEM (Optional Evaluation Module)
The easiest way to get started and have immediate success is to purchase the CC264BPA-TIEM. The front side of the board has a power switch and the CC264BPA Module, and the reverse side of the board houses a coin-cell battery holder, a programming header (J6), and two expansion headers. The XDS110 Debug Devpack plugs directly into the programming header (J6) and the battery holder is used to prevent pin mismatch (it is only possible to plug the programmer into the board in the correct orientation).
Front and reverse of the CC264BPA-TIEM module.
Backup and Restore the CC264BPA Evaluation Module
SmartRF Flash Programmer 2 showing a "Read Flash to File" operation and a write operation.
- To Backup
- Download and install TI's SmartRF Flash Programmer 2
- Connect the XDS110 Debug DevPack to the CC264BPA-TIEM and to your computer using a micro-USB cable.
- Use a battery or the wires from the DevPack to power the device. Use the selector switch on the front of the board to select the power source.
- Open SmartRF Flash Programmer 2 and select the CC2640 under "Connected Devices".
- Select the "Edit" tab.
- Select "Read" to read the data from flash memory.
- Select "Read Flash to File" to save it .
- To Restore
- Connect the XDS110 DebugDevPack to the CC264BPA-TIEM and to your computer using a micro-USB cable.
- Use a battery or the wires from the TI DevPack to power the device. Use the selector switch on the front of the board to select the power source.
- Open SmartRF Flash Programmer 2 and select the CC2640 under "Connected Devices".
- Select the "Main" Tab.
- Click Browse and look for the file you saved earlier (ends in .bin).
- Under Actions, select "Erase", "Program", "Verify".
- Click on the triangle in the lower right-hand corner of the Actions box to Erase, Program, and Verify your device.
Evaluation Module and a USB-Serial Converter
While working with the following projects, your power level and data signal level should always be around 3.3 V, permanent damage to the CC2640 IC will occur if you exceed 4.1 V on any input (with a suggested max of 3.8 V).
The Data Exchanger Firmware that is pre-installed on the CC264 Evaluation Module by GT-tronics allows for simple UART communication between the module and the iPhone DataExchanger app.
Image from GT-Tronics DataExchanger-AT User Guide shows connections to a 3.3 V USB to UART converter.
Alternatively, you can use a 5V USB-UART or MCU to connect to the module. The necessary connections are shown in the diagram below.
Image shows necessary connections to run simple UART example with a 5V MCU.
For code examples to communicate with a device that has command mode, see the second program in my article on the HC12 Wireless Transceiver (HC12 Send/Receive Example Program 2).
You can now use the DataExhchanger App to pass information to and from your iPhone. For additional information, please reference the GT-tronics DataExchanger-AT User Guide, also provided in the pdf documents below. Contact GT-tronics if you would like the source code for the iOS or Android app to build your own custom application.
Preparing the CC264BPA Module
You need to make several connections to the CC264BPA Module to program it. It consists of 26 castellated vias that are spaced 0.05" apart -- which is small, but not so small that wires cannot be hand-soldered to the board. Alternatively, if you are lucky enough to have access to a laser cutter/engraver, you can use the files I provided below to create a "Bed of Nails" to connect to the board for batch programming. Pin 15 (test reset not) should be connected to supply voltage with a ~10 kΩ pull-up resistor. All other wires are direct connections and should be kept as short as possible.
To program the device, pins 8 through 15 must be connected to the TI XDS110 Debug Programmer.
Optional "Bed-of-Nails" in disassembled form and assembled with the least number of necessary laser-cut parts.
Code Composer Studio
Texas Instruments (TI) Code Composer Studio v7.0 (CCS7) is a fully-featured Integrated Development Environment (free download here, or use online here). CCS7 can manage projects, download resources, and provides free video and free interactive training that helps users better understand the software. If you have difficulties using the software, visit the TI support page that provides access to the CCS MediaWiki, CCS troubleshooting guide, FAQs, and Development Tools Support Forum. For assistance with compiler questions, visit the Compiler E2E forum.
See the video from TI below to learn more about Code Composer Studio.
First Project Builds
This section of the article provides the steps to install Code Composer Studio, program, and then debug your first project—a Bluetooth Peripheral project.
Note: The following background information is taken in abridged form from Texas Instruments CC2640 and CC2650 SimpleLink Bluetooth Low Energy Software Stack 2.2.1 Developer's Guide (Section 1).
The CC2640 is a multicore System-On-Chip device that uses an ARM Cortex-M0 Radio Core to handle the physical layer of communications "1-Mbps adaptive frequency-hopping GFSK (Gaussian frequency-shift keying." The RF core functions autonomously and handles "all the low-level radio control and processing associated with the physical layer and parts of the link layer." Developers do not program the radio core.
The main system core is an ARM Cortex M3 processor that interacts with the radio core and provides access to a variety of peripherals through I²C, SPI, UART, I²S. The chip has multiple GPIOs and a 12-bit ADC, and functions using a Real-Time Operating System (RTOS) that is designed to process sensor data without buffer delays.
An ultralow power (ULP) 16-bit sensor controller CPU can interface external analog and digital sensors to collect data while the rest of the chip is in sleep mode.
This design allows long duration low power data acquisition that only requires the other processors to leave sleep mode long enough to transmit a packet of data -- making it ideal for designs that function for long periods on small watch-sized batteries.
SimpleLink CC22640 block diagram from CC2640 datasheet.
The CC2640 can be used as a complete System-on-chip solution, or as a Simple Network Processor, where an additional microcontroller communicates with and controls the CC2640 via serial communication (UART or SPI). The "Simple Network Processor implements the controller and host layers of the BLE-stack" and "exposes an interface for scheduling communication between the stack and an external MCU."
Getting Started and Compiling Your First Project
Detailed installation instructions (including screenshots) are provided in the GT-tronics build guide below. The pdf below details the steps needed to download and install CCS, the BLE software stack, a preconfigured peripheral project provided by GT-tronics, and a general guide to install sample TI projects. The goal of the guide is to get users started using a minimal amount of information. You should refer to the Developers Guide for complete instructions.
If the project does not load, the most likely problem is electrical -- double check all connections. If the project does not compile, there might be a problem with the Code Composer Studio installation or configuration, double check the detailed instruction guide, and if problems persist, try the installation on a different computer, in a new workspace, or check the Code Composer Forums.
The programs examples and pre-compiled binaries located in the project folders are designed to work with Ti evaluation modules (em), booster packs (bp), Launchpad (lp), Remote Control (rc), and cannot be loaded directly into the CC264BPA, but the code does allow you to better understand how the software works. You can find the corresponding project information in Chapter 12 of the Texas Instruments Developers Guide and on ti.com.
See the document above titled "Building Firmware for the CC264BPA" that provides information on creating your own firmware.
The CC2650 SensorTag has a variety of sensors (light, accelerometer, magnetometer, gyroscope, barometer), two buttons, two LEDs and a buzzer packed into a tiny package that should allow you to understand I²C, SPI, and GPIO interfacing with the CC26x0 devices.
Project with "np" in the filename use the CC2640 as a network processor. Remember that you must perform level shifting before attaching it to a 5V microcontroller -- you will permanently damage the device if you exceed 4.1 V at any time.
This is a simple introduction to Code Composer Studio that programs a CC2640 BLE module, but there is a good chance that it does not have the functionality that you want for your personal project. So start by reading and understanding the Developer's Guide, followed by the code in the example projects we just compiled and loaded, and the code for other provided example "app" projects in "c:\ti\simplelink\ble_sdk_2_02_01_18". Texas Instruments recommends beginning with projects that are prepended with "simple_". Additional software examples are available on github.com/ti-simplelink. Additional ARM Compiler Versions can be installed with Help>Install New Software and software examples can be installed with the Resource Explorer. Old XDCTools versions are available here. All CC2650 BLE projects can be used with the CC2640 SOC.
If this is the type of project that interests you, and you would like to see more, please let us know in the comment section below.
Give this project a try for yourself! Get the BOM.