This article deals with the information regarding basic setup of CC2541 SoC (system-on-chip) as an Altbeacon advertisement beacon. But in order to begin with that, we must first understand the components used.
What is CC2541?
It is a power-optimized true system-on-chip (SoC) developed by Texas Instruments that is implemented in Bluetooth Low Energy (BLE) and proprietary 2.4-GHz applications. It combines RF transceiver with an industry-standard enhanced, low-power 8051 microcontroller(MCU). The MCU consists of in-system programmable flash memory (128 or 256 KB) and 8 KB RAM. This chip supports 250-kbps, 500-kbps, 1-Mbps and 2-Mbps Data Rates and has excellent receiver sensitivity (-94 dBm at 1-Mbps). It also features Bluetooth V4.0 compliant protocol stack for single-mode BLE solution which can be used for creating a proximity beacon.
To program this SoC, we require another device from Texas Instruments called CC Debugger.
What is CC Debugger?
Texas Instruments have developed this programmer which is primarily used for Flash programming and debugging software running on CCxxxx devices.
This device requires USB driver which can be installed by downloading a PC tool called SmartRF Flash Programmer from T.E. website.
To develop code and burn it to the device, we need another PC tool called IAR Embedded Workbench for 8051 from IAR Systems.
When the debugger successfully establishes a connection with the device, the LED goes green. If not connected it becomes red.
Connecting CC Debugger with a device
This debugger consists of a mini USB slot on one side and a 10 pin slot on the other. Each pin has a unique purpose and has to be connected in the correct manner with the device in order to establish a connection. The pinout configuration is as follows:
Minimum connection to the device for successful debugging is Debug Data (DD), Debug Clock (DC), Reset, VDD, and GND.
At times, the device might not get recognized by the debugger even after connecting the above-mentioned pins. In those cases, we need to connect Target Voltage Sense pin to the 3.3V pin on the device along with pin 9.
Creating a BLE Beacon (Proximity Beacon)
Beacons or Proximity Beacons are nothing but devices that transmit signals to different devices at small intervals using Bluetooth Low Energy technology. These devices have a specific range in which they operate. Generally, it is under 300 feet.
To be able to create a proximity beacon, we first need to understand the protocol on which the beacon would be based. There are few protocols that can be followed namely, iBeacon (Apple devices), Eddystone and AltBeacon.
Here, we will be discussing Altbeacon protocol.
The transmitted signal carries a certain message. We refer to them as proximity beacon advertisements. For transmitting a signal, beacons need to follow a certain format in which the contents of the message are encoded. This is used by the receiving devices to identify beacon and to calculate the relative distance to the beacon. This functionality is not restricted to any specific device but can be implemented in any device that is BLE compliant. For example, Smartphones running above Android version 5 can easily download certain apps that support this feature.
AltBeacon Protocol Format Specification
AltBeacons have 26 bytes available for user modification out of 28 bytes. This increases the amount of data that can be delivered per message.
AD Length and AD Type, 1 byte each is set by the BLE stack and cannot be modified by the user.
- #AD Length (1 Byte): This byte represents the length of type and data part contained in the data structure. It is given a value of 0x1B.
- #AD Type (1 Byte): This byte represents the type of data structure. It is given a value of 0xFF.
- #MFG ID (2 Bytes): These 2 bytes contain the manufacturer’s unique company identifier code.
- #BEACON CODE (2 Bytes): It is the AltBeacon advertisement code. It is given a value of 0xBEAC.
- #BEACON ID (20 Bytes): These 20 Bytes can be set by the user and are used for uniquely identifying a beacon. These can be either numbers or alphabets or combination of both.
- #REFERENCE RSSI (1 Byte): 1 byte signed value (0 to -127) representing the average received signal strength at 1 meter from the beacon. It can be given a 0 value.
- #MFG RSVD (1 Byte): This 1 Byte can be customized for adding extra identification. For example, one can add an alphabet to distinguish between a transmitter and receiver following the same beacon ID.
Requirements for transmitting AltBeacon
In this tutorial, we have used JDY08 module which is a self-contained device in itself. It contains CC2541 with all the required components to successfully run and program. Here is the link to its datasheet: JDY08
We just need to connect the respective programmable pins and power pins using the CC Debugger as demonstrated earlier in this tutorial. A custom made PCB with JDY08 looks something like this:
Image is taken from source
In order to program and enable the device, we need to download BLE Stack v1.4.2 from TI website. Here is the link: BLE Stack
After Installing, you will find a ‘Texas Instruments’ folder on your local disk.
Go to C:\Texas Instruments\BLE-CC254x-220.127.116.11\Documents\TI_BLE_Software_Developer’s_Guide. This document contains all the necessary information required to be able to successfully program a CC2541. Please note that you will need to go through all the library files mentioned to better understand the flow of the program, especially GAP library.
There are a lot of BLE applications provided by TI in the ‘Projects’ folder. We will use one of the projects as an example and insert our own code for demonstrating the operation.
Go to C:\Texas Instruments\BLE-CC254x-18.104.22.168\Projects\ble\SimpleBLEBroadcaster\CC2541DB and open ‘SimpleBLEBroadcaster.eww’. Please note that in order to open this file you need IAR Embedded Workbench in your computer as specified earlier in this tutorial. Once the program loads up, open ‘simpleBLEBroadcaster.c’ tab and scroll over to ‘advertData’. This array has a maximum size of 31 bytes. This is where the advertisement data is stored. As per the program, it is set to send some random Bluetooth packet on initialization. We will change it to fit our own requirement. It is recommended to go through GAP library to understand this in a better way because the GAP layer of the BLE protocol stack is responsible for connection functionality. It handles the device’s access modes and procedures including device discovery, link establishment, link termination, initiation of security features, and device configuration.
We need to comment out the pre-designated code.
/*0x02, GAP_ADTYPE_FLAGS, GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED, 0x04, GAP_ADTYPE_MANUFACTURER_SPECIFIC, 1, 2, 3*/
Now implement this code inside advertData :
0x02, // length of the data /*Flags set the device to use limited discoverable mode (advertises for 30 seconds at a time) instead of general discoverable mode (advertises indefinitely)*/ GAP_ADTYPE_FLAGS, GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED | GAP_ADTYPE_FLAGS_LIMITED, 0x1B, //length of this data including the data type GAP_ADTYPE_MANUFACTURER_SPECIFIC, //manufacturer specific advertisement data /* The beacon device manufacturer's company identifier code. (in big endian) */ HI_UINT16(TI_COMPANY_ID), LO_UINT16(TI_COMPANY_ID), /* The AltBeacon advertisement code 0xBEAC (in big endian) */ HI_UINT16(0xBEAC), LO_UINT16(0xBEAC), /* A 20-byte value uniquely identifying the beacon */ /*Please note that this 20-byte value can be customized and is on the programmer's wish*/ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 0, /* 0dBm */ /* A 1-byte value representing the average received signal strength at 1m from the advertiser */ 'C'/* Reserved for use by the programmer to implement special features */
After inserting this code, just rebuild and download into the device.
Your device should now be acting as a beacon. To check, just download any beacon locator app from appstore or playstore. I have used an app called ‘Locate’ for Android. The result will look something like this: