TI BLE Sample Applications Guide

TI_BLE_Sample_Applications_Guide

User Manual: Pdf

Open the PDF directly: View PDF PDF.
Page Count: 37

DownloadTI BLE Sample Applications Guide
Open PDF In BrowserView PDF
Texas Instruments CC2540/41
Bluetooth® Low Energy
Sample Applications Guide
v1.3.2

Document Number: SWRU297

Copyright © 2011-2013 Texas Instruments, Inc.

Table Of Contents
TABLE OF CONTENTS .............................................................................................................................. 2
REFERENCES .............................................................................................................................................. 5
1

OVERVIEW........................................................................................................................................... 6
1.1

2

INTRODUCTION ................................................................................................................................. 6

BLOOD PRESSURE SENSOR ............................................................................................................ 6
2.1
PROJECT OVERVIEW ......................................................................................................................... 6
2.1.1
User Interface .......................................................................................................................... 6
2.1.2
Basic Operation ....................................................................................................................... 6
2.2
SOFTWARE DESCRIPTION.................................................................................................................. 7
2.2.1
Initialization ............................................................................................................................. 7
2.2.2
Event Processing ..................................................................................................................... 7
2.2.3
Callbacks ................................................................................................................................. 7
2.2.4
Sending Blood Pressure Measurement Indications ................................................................. 8
2.2.5
Sending Intermediate Measurement Notifications ................................................................... 8
2.2.6
Blood Pressure Measurement .................................................................................................. 8

3

HEALTH THERMOMETER .............................................................................................................. 8
3.1
PROJECT OVERVIEW ......................................................................................................................... 8
3.1.1
User Interface .......................................................................................................................... 8
3.1.2
Basic Operation ....................................................................................................................... 9
3.2
SOFTWARE DESCRIPTION.................................................................................................................. 9
3.2.1
Initialization ............................................................................................................................. 9
3.2.2
Event Processing ................................................................................................................... 10
3.2.3
Callbacks ............................................................................................................................... 10
3.2.4
Sending Temperature Indications .......................................................................................... 10
3.2.5
Sending Intermediate Measurement Notifications ................................................................. 10
3.2.6
Sending Interval Change Indications ..................................................................................... 10
3.2.7
Thermometer Measurement Format ...................................................................................... 11

4

HEART RATE SENSOR .................................................................................................................... 11
4.1
PROJECT OVERVIEW ....................................................................................................................... 11
4.1.1
User Interface ........................................................................................................................ 11
4.1.2
Basic Operation ..................................................................................................................... 11
4.2
SOFTWARE DESCRIPTION................................................................................................................ 11
4.2.1
Initialization ........................................................................................................................... 12
4.2.2
Event Processing ................................................................................................................... 12
4.2.3
Callbacks ............................................................................................................................... 12
4.2.4
Sending Notifications ............................................................................................................. 12

5

CYCLING SPEED AND CADENCE (CSC) SENSOR .................................................................... 12
5.1
PROJECT OVERVIEW ....................................................................................................................... 13
5.1.1
User Interface ...................................................................................................................... 13
5.1.2
Basic Operation ................................................................................................................... 13
5.2
SOFTWARE DESCRIPTION................................................................................................................ 13
5.2.1
Initialization .......................................................................................................................... 14
5.2.2
Event Processing ................................................................................................................ 14
5.2.3
Callbacks .............................................................................................................................. 14
5.2.4
Sending Notifications .......................................................................................................... 14
5.2.5
Confirming Indications ........................................................................................................ 14
5.2.6
Reading from the Sensor ................................................................................................... 14
5.2.7
Writing to the Sensor .......................................................................................................... 15
5.2.8
Neglect Timer ...................................................................................................................... 15

6

RUNNING SPEED AND CADENCE (RSC) SENSOR .................................................................... 15
6.1

PROJECT OVERVIEW ....................................................................................................................... 15

Page 2 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

SWRU297 Version 1.3.2

6.1.1
User Interface ...................................................................................................................... 15
6.1.2
Basic Operation ................................................................................................................... 16
6.2
SOFTWARE DESCRIPTION................................................................................................................ 16
6.2.1
Initialization .......................................................................................................................... 16
6.2.2
Event Processing ................................................................................................................ 16
6.2.3
Callbacks .............................................................................................................................. 17
6.2.4
Sending Notifications .......................................................................................................... 17
6.2.5
Confirming Indications ........................................................................................................ 17
6.2.6
Reading from the Sensor ................................................................................................... 17
6.2.7
Writing to the Sensor .......................................................................................................... 17
6.2.8
Neglect Timer ...................................................................................................................... 18
7

GLUCOSE COLLECTOR ................................................................................................................. 18
7.1
PROJECT OVERVIEW ....................................................................................................................... 18
7.1.1
User Interface ........................................................................................................................ 18
7.1.2
Basic Operation ..................................................................................................................... 18
7.1.3
Record Filter Configuration .................................................................................................. 19
7.2
SOFTWARE DESCRIPTION................................................................................................................ 19
7.2.1
Initialization ........................................................................................................................... 19
7.2.2
Event Processing ................................................................................................................... 19
7.2.3
Callbacks ............................................................................................................................... 19
7.2.4
Service Discovery .................................................................................................................. 20
7.2.5
Service Configuration ............................................................................................................ 20
7.2.6
Record Access Control Point ................................................................................................. 20

8

GLUCOSE SENSOR ........................................................................................................................... 20
8.1
PROJECT OVERVIEW ....................................................................................................................... 20
8.1.1
User Interface ........................................................................................................................ 20
8.1.2
Basic Operation ..................................................................................................................... 21
8.2
SOFTWARE DESCRIPTION................................................................................................................ 21
8.2.1
Initialization ........................................................................................................................... 21
8.2.2
Event Processing ................................................................................................................... 21
8.2.3
Callbacks ............................................................................................................................... 21
8.2.4
Sending Notifications and Indications ................................................................................... 22
8.2.5
Record Access Control Point Processing .............................................................................. 22

9

HID ADVANCED REMOTE CONTROL ........................................................................................ 22

10

HID EMULATED KEYBOARD .................................................................................................... 22

10.1 PROJECT OVERVIEW ....................................................................................................................... 22
10.1.1
User Interface ........................................................................................................................ 23
10.1.2
Basic Operation ..................................................................................................................... 23
10.2 SOFTWARE DESCRIPTION................................................................................................................ 23
10.3 HIDEMUKBD APPLICATION ............................................................................................................ 23
10.3.1
Initialization ........................................................................................................................... 23
10.3.2
Event Processing ................................................................................................................... 23
10.3.3
Callbacks ............................................................................................................................... 24
10.3.4
Sending Notifications ............................................................................................................. 24
10.4 HID DEVICE PROFILE ..................................................................................................................... 24
10.4.1
Initialization ........................................................................................................................... 24
10.4.2
Event Processing ................................................................................................................... 24
10.4.3
Callbacks ............................................................................................................................... 24
10.4.4
GATT Read and Write Callbacks ........................................................................................... 25
10.4.5
Mapping HID Reports to HID Characteristics ...................................................................... 25
10.4.6
Sending and Receiving HID Reports ..................................................................................... 25
10.4.7
Advertising and Connection Procedures ............................................................................... 25
11

HOSTTESTRELEASE- BLE NETWORK PROCESSOR .......................................................... 25

12

KEYFOBDEMO .............................................................................................................................. 25

12.1

PROJECT OVERVIEW ....................................................................................................................... 26
Page 3 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

SWRU297 Version 1.3.2

12.1.1
User Interface ........................................................................................................................ 26
12.1.2
Battery Operation .................................................................................................................. 26
12.1.3
Accelerometer Operation ....................................................................................................... 26
12.1.4
Keys ....................................................................................................................................... 26
12.1.5
Proximity ............................................................................................................................... 27
12.2 SOFTWARE DESCRIPTION................................................................................................................ 27
12.2.1
Initialization ........................................................................................................................... 27
12.2.2
Event Processing ................................................................................................................... 27
12.2.3
Callbacks ............................................................................................................................... 27
13
13.1
13.2

SENSORTAG................................................................................................................................... 28
OPERATION..................................................................................................................................... 28
SENSORS ......................................................................................................................................... 28

14

SIMPLEBLECENTRAL ................................................................................................................ 28

15

SIMPLEBLEPERIPHERAL .......................................................................................................... 29

16

TIMEAPP- BLE WATCH .............................................................................................................. 29

16.1 PROJECT OVERVIEW ....................................................................................................................... 29
16.1.1
User Interface ........................................................................................................................ 29
16.1.2
Basic Operation ..................................................................................................................... 29
16.2 SOFTWARE DESCRIPTION................................................................................................................ 30
16.2.1
Initialization ........................................................................................................................... 30
16.2.2
Event Processing ................................................................................................................... 30
16.2.3
Callbacks ............................................................................................................................... 31
16.2.4
Service Discovery .................................................................................................................. 31
16.2.5
Service Configuration ............................................................................................................ 31
16.2.6
Handling Indications and Notifications ................................................................................. 31
16.2.7
Clock Time ............................................................................................................................. 31
17

SERIAL BOOTLOADER ............................................................................................................... 32

17.1 BASIC OPERATION .......................................................................................................................... 32
17.1.1
Build and Flash the SBL ........................................................................................................ 32
17.1.2
Build the Project to be Bootloaded ........................................................................................ 32
17.1.3
Download the User Project Image (.bin) ............................................................................... 32
18

USB BOOTLOADER ...................................................................................................................... 32

18.1 BASIC OPERATION .......................................................................................................................... 32
18.1.1
Flash UBL .............................................................................................................................. 32
18.1.2
Build the Project to be Bootloaded ........................................................................................ 32
18.1.3
Download the User Project Image (.bin) ............................................................................... 33
19
19.1
19.2
19.3
20
20.1

OVER AIR DOWNLOAD .............................................................................................................. 33
TARGET REQUIREMENTS ................................................................................................................ 33
SERVER REQUIREMENTS ................................................................................................................. 33
OAD DEVELOPER’S GUIDE ............................................................................................................ 33
GENERAL INFORMATION ......................................................................................................... 35
DOCUMENT HISTORY ..................................................................................................................... 35

21

ADDRESS INFORMATION .......................................................................................................... 35

22

TI WORLDWIDE TECHNICAL SUPPORT ............................................................................... 35

Page 4 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

SWRU297 Version 1.3.2

References
Included with Texas Instruments Bluetooth Low Energy v1.3.2 Stack Release (All path and file
references in this document assume that the BLE development kit software has been installed to
the default path C:\Texas Instruments\BLE-CC254x-1.3.2\):
[1] Texas Instruments Bluetooth® Low Energy Software Developer’s Guide (SWRU271B)
C:\Texas Instruments\BLE-CC254x-.3.2\Documents\TI_BLE_Software_Developer's_Guide.pdf
Adopted Bluetooth specifications (which can be downloaded from
https://www.bluetooth.org/Technical/Specifications/adopted.htm):
[2] Blood Pressure Profile (BLP) Specification v1.0
[3] Blood Pressure Service (BLS) Specification v1.0
[4] Health Thermometer Profile (HTP) Specification v1.0
[5] Health Thermometer Service (HTS) Specification v1.0
[6] Heart Rate Profile (HRP) Specification v1.0
[7] Heart Rate Service (HRS) Specification v1.0
[8] HID over GATT Profile (HOGP) Specification v1.0
[9] HID Service (HIDS) Specification v1.0
[10] Scan Parameters Profile (ScPP) v1.0
[11] Scan Parameters Service (ScPS) v1.0
[12] Device Information Service (DIS) Specification v1.1
[13] Battery Service (BAS) specification v1.0
[14] Proximity Profile (PXP) Specification v1.0
[15] Find Me Profile (FMP) Specification v1.0
[16] Link Loss Service (LLS) Specification v1.0
[17] Immediate Alert Service (IAS) Specification v1.0
[18] Tx Power Service (TPS) Specification v1.0
[19] Time Profile (TIP) Specification v1.0
[20] Alert Notification Profile (ANP) Specification v1.0
[21] Phone Alert Status (PASP) Specification v1.0
[22] Running Speed and Cadence Profile
[23] Running Speed and Cadence Service
[24] Cycling Speed and Cadence Profile
[25] Cycling Speed and Cadence Service

Page 5 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

1

SWRU297 Version 1.3.2

Overview

The purpose of this document is to give an overview of the sample applications that are included
in the Texas Instruments CC2540/41 Bluetooth® low energy (BLE) software development kit. It is
recommended that you read [1] before attempting to use these sample applications, as some
knowledge of the CC2540/41 BLE protocol stack and software is required.
1.1

Introduction

Version 1.3.2 of the Texas Instruments CC2540/41 BLE software development kit includes
several sample applications implementing a variety of GATT-based profiles. Some of these
implementations are based on specifications that have been adopted by the Bluetooth Special
Interest Group (BT SIG), while others are based on specifications that are a work-in-progress and
have not been finalized. In addition, some applications are not based on any standardized profile
being developed by the BT SIG, but rather are custom implementations developed by Texas
Instruments. In order to interoperate with other Bluetooth low energy devices (such as a mobile
phone), an application would need to be written on the other device which implements the proper
GATT client and/or server functionality that matches the CC2540/41 sample application. The
status of the implementation of each profile/application is included in this document.
The information in this guide specifically mentions only CC2540 projects; however all of the
applications and configurations (with the exception of those that use the USB interface) also can
run on the CC2541. Be sure to open the correct project file depending on the chipset that is being
used.

2

Blood Pressure Sensor

This sample project implements the Blood Pressure profiles in a BLE peripheral device to provide
an example blood pressure monitor using simulated measurement data. The application
implements the "Sensor" role of the blood pressure profile. The project is based on the adopted
profile and service specifications for Blood Pressure ([2] and [3]). The project also includes the
Device Information Service ([12]).
The project can be opened with the following IAR workspace file:
C:\Texas Instruments\BLE-CC254x-1.3.2\
Projects\ble\BLoodPressure\CC2540DB\bloodpressure.eww
2.1

Project Overview

The project structure is very similar to that of the SimpleBLEPeripheral project. The APP directory
contains the application source code and header files. The project contains two configurations.
-

CC2540DK-MINI Keyfob Slave: using the keyfob hardware platform.

-

CC2540 Slave: using the SmartRF platform.

2.1.1

User Interface

There are two button inputs for this application.
KeyFob Right or SmartRF Joystick Right
When not connected, this button is used to toggle advertising on and off. When in a connection,
this increases the value of various measurements.
KeyFob Left or SmartRF Joystick Up
This button cycle through different optional measurement formats.
2.1.2

Basic Operation

Power up the device and press the right button to enable advertising. From a blood pressure
collector peer device, initiate a device discovery and connection procedure to discover and
connect to the blood pressure sensor. The peer device should discover the blood pressure
service and configure it to enable indication or notifications of the blood pressure measurement.
Page 6 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

SWRU297 Version 1.3.2

The peer device may also discover the device information service for more information such as
mfg and serial number.
Once blood pressure measurements have been enabled the application will begin sending data to
the peer containing simulated measurement values. Pressing the left button cycles through
different data formats as follows:







MMHG | TIMESTAMP | PULSE | USER | STATUS
MMHG | TIMESTAMP
MMHG
KPA
KPA | TIMESTAMP
KPA |TIMESTAMP | PULSE

If the peer device initiates pairing, the blood pressure sensor will request a passcode. The
passcode is “000000”.
Upon termination, the BPM will not begin to advertising again until the button is pressed.
The peer device may also query the blood pressure for read only device information. Further
details on the supported items are listed in the GATT_DB excel sheet for this project. Examples
are model number, serial number, etc.
2.2

Software Description

The application is implemented in the file bloodpressure.c.
2.2.1

Initialization

The initialization of the application occurs in two phases: first, the Bloodpressure_Init function is
called by the OSAL. This function configures parameters in the peripheral profile, GAP, and GAP
bond manager. It also sets up the blood pressure service along with standard GATT and GAP
services in the attribute server. Then it sets an OSAL START_DEVICE_EVT event. This triggers
the
second
phase
of
the
initialization,
which
can
be
found
within
the
Bloodpressure_ProcessEvent function. During this phase, the GAPRole_StartDevice function
is called to set up the GAP functions of the application. Then GAPBondMgr_Register is called to
register with the bond manager.
2.2.2

Event Processing

The application has two main event processing functions, Bloodpressure_ProcessEvent and
Bloodpressure_ProcessOSALMsg.
Function Bloodpressure_ProcessEvent handles events as follows:







SYS_EVENT_MSG: Service the OSAL queue and process OSAL messages.
BP_START_DEVICE_EVT: Start the device, as described in the previous section.
BP_START_DISCOVERY_EVT: Start discovery, search for time service on collector.
TIMER_BPMEAS_EVT: Perform final measurement
BP_TIMER_CUFF_EVT: Perform a cutoff measurement
BP_DISCONNECT_EVT: Disconnect after sending measurement

Function Bloodpressure_ProcessOSALMsg handles OSAL messages as follows:


2.2.3

KEY_CHANGE: Handle key presses.
GATT_MSG_EVENT: This will handle reception of time information from collector.
Callbacks

The application callback functions are as follows:


PeripheralStateNotificationCB: This is the GAP event callback. It processes GAP
events for startup and link connect/disconnect.

Page 7 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2




2.2.4

SWRU297 Version 1.3.2

bpServiceCB: This is the blood pressure service callback. It handles enabling or
disabling measurements.
TimeAppPairStateCB: This is a GAPBOND callback to handle pairing states.
TimeAppPasscodeCB: Returns the passcode of 0.
Sending Blood Pressure Measurement Indications

The application sends indication of the blood pressure measurement when configured to do so by
the peer device.
When the peer device configures the blood pressure measurement for indication the application
will receive a blood pressure service callback. The application starts a timer to begin periodic
simulated blood pressure measurements. When the timer expires the application calls
bpSendStoredMeas to build and send a measurement using the blood pressure service API. The
application expects the peer device to send back an indication confirmation.
2.2.5

Sending Intermediate Measurement Notifications

The application sends notification of the blood pressure measurement when configured to do so
by the peer device.
When the peer device configures the blood pressure measurement for notification the application
will receive a blood pressure service callback. The application starts a timer to begin periodic
simulated blood pressure measurements. When the timer expires the application calls
bloodPressureIMeasNotify to build and send a measurement using the blood pressure service
API.
2.2.6

Blood Pressure Measurement
Blood Pressure Measurement
Value

Flags

Systolic
Size

3

1
octet

2 octets

Diastolic
2 octets

Time
Stamp

Pulse
Rate

User
ID

MAP
2 octets

7 octets

2 octets

1 octet

Health Thermometer

This sample project implements a Health Thermometer and Device Information profile in a BLE
peripheral device to provide an example health thermometer application using simulated
measurement data. The application implements the "Sensor" role of the Health Thermometer
profile. The project is based on the adopted profile and service specifications for Health
Thermometer (see [4] and [5]). The project also includes the Device Information Service ([12]).
The project can be opened with the following IAR workspace file:
C:\TexasInstruments\BLE-CC254x1.3.2.1\Projects\ble\Thermometer\CC2540DB\thermometer.eww
3.1

Project Overview

The project structure is very similar to that of the SimpleBLEPeripheral project. The APP directory
contains the application source code and header files. The project contains two configurations.


3.1.1

CC2540DK-MINI Keyfob Slave: using the keyfob hardware platform.
CC2540 Slave: using the SmartRF platform.
User Interface

There are two button inputs for this application.
KeyFob Right | SmartRF Joystick Right
When not connected and not configured to take measurements, this button is used to toggle
advertising on and off.
Page 8 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

SWRU297 Version 1.3.2

When in a connection or configured to take measurements, this increases the temperature by 1
degree Celsius. After 3 degrees in temperature rise, the interval will be set to 30 seconds and if
configured, this will indicate to the peer an interval change initiated at the thermometer.
KeyFob Left | SmartRF Joystick Up
This button cycle through different measurement formats.
3.1.2

Basic Operation

Power up the device and press the right button to enable advertising. From a thermometer
collector peer device, initiate a device discovery and connection procedure to discover and
connect to the thermometer sensor. The peer device should discover the thermometer service
and configure it to enable indication or notifications of the thermometer measurement. The peer
device may also discover the device information service for more information such as mfg and
serial number.
Once thermometer measurements have been enabled the application will begin sending data to
the peer containing simulated measurement values. Pressing the left button cycles through
different data formats as follows:







CELCIUS | TIMESTAMP | TYPE
CELCIUS | TIMESTAMP
CELCIUS
FARENHEIT
FARENHEIT | TIMESTAMP
FARENHEIT | TIMESTAMP | TYPE

If the peer device initiates pairing, the the HT will request a passcode. The passcode is “000000”.
The HT operates in the following states:








Idle – In this state, the thermometer will wait for the right button to be pressed to start
advertising.
Idle Configured – The thermometer waits the interval before taking a measurement and
proceeding to Idle Measurement Ready state.
Idle Measurement Ready – The thermometer has a measurement ready and will
advertise to allow connection. The thermometer will periodically advertise in this state.
Connected Not Configured - The thermometer may be configured to enable
measurement reports. The thermometer will not send stored measurements until the
CCC is enabled. Once connection is established, the thermometer sets a timer to
disconnect in 20 seconds.
Connected Configured - The thermometer will send any stored measurements if CCC is
set to send measurement indications.
Connected Bonded - The thermometer will send any stored measurements if CCC was
previously set to send measurement indications.

The peer device may also query the thermometers read only device information. Examples are
model number, serial number, etc.
3.2

Software Description

The application is implemented in the file thermometer.c.
3.2.1

Initialization

The initialization of the application occurs in two phases: first, the Thermometer_Init function is
called by the OSAL. This function configures parameters in the peripheral profile, GAP, and GAP
bond manager. It also sets up the thermometer service along with standard GATT and GAP
services in the attribute server. Then it sets an OSAL START_DEVICE_EVT event. This triggers
the
second
phase
of
the
initialization,
which
can
be
found
within
the
Thermometer_ProcessEvent function. During this phase, the GAPRole_StartDevice function is
Page 9 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

SWRU297 Version 1.3.2

called to set up the GAP functions of the application. Then GAPBondMgr_Register is called to
register with the bond manager.
3.2.2

Event Processing

The application has two main event processing functions, Thermometer_ProcessEvent and
Thermometer_ProcessOSALMsg.
Function Thermometer_ProcessEvent handles events as follows:







SYS_EVENT_MSG: Service the OSAL queue and process OSAL messages.
START_DEVICE_EVT: Start the device, as described in the previous section.
TH_START_DISCOVERY_EVT: Start discovery, search for time service on collector.
TH_PERIODIC_MEAS_EVT: Start a measurement.
TH_PERIODIC_IMEAS_EVT: Send immediate measurement.
TH_DISCONNECT_EVT: Terminate connection.

Function Thermometer_ProcessOSALMsg handles OSAL messages as follows:


3.2.3

KEY_CHANGE: Handle key presses.
GATT_MSG_EVENT: This will handle reception of time information from collector.
Callbacks

The application callback functions are as follows:




3.2.4

PeripheralStateNotificationCB: This is the GAP event callback. It processes GAP
events for startup and link connect/disconnect.
ThermometerCB: This is the thermometer service callback. It handles enabling or
disabling measurements.
TimeAppPairStateCB: This is a GAPBOND callback to handle pairing states.
TimeAppPasscodeCB: Returns the passcode of 0.
Sending Temperature Indications

The application enables indication of the thermometer measurement when configured to do so by
the peer device.
When the peer device configures the thermometer measurement for indication the application will
receive a thermometer service callback. The application starts a timer to begin periodic simulated
thermometer
measurements.
When
the
timer
expires
the
application
calls
thermometerMeasIndicate to build and store a measurement. Once a measurement is ready,
the thermometer will enter connectable state and send advertisements. If the peer device
connects and the CCC is enabled, the thermometer will send the stored measurements. The
thermometer expects the peer device to send back an indication confirmation for each indication
sent.
3.2.5

Sending Intermediate Measurement Notifications

The application sends notification of the thermometer measurement when configured to do so by
the peer device.
When the peer device configures the thermometer measurement for notification the application
will receive a thermometer service callback. The application starts a timer to begin periodic
simulated thermometer measurements. When the timer expires the application calls
thermometerIMeasIndicate to build and send a measurement using the thermometer service
API.
3.2.6

Sending Interval Change Indications

If the CCC for interval change is enabled, the thermometer will send an indication to the peer if
the interval is changed by the thermometer. This can be triggered by pressing the right button
three times which will increase the simulated temperature by 3 degrees and also reset the interval
to 30 seconds.
Page 10 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

3.2.7

Size
Units

4

SWRU297 Version 1.3.2

Thermometer Measurement Format
Flags

Temperature
Measurement Value

Time Stamp
(if present)

Temperature Type
(if present)

1 octet

4 octets

0 or 7 octets

0 or 1 octet

None

Based on bit 0 of Flags
field

Smallest unit
in seconds

None

Heart Rate Sensor

This sample project implements the Heart Rate and Battery profiles in a BLE peripheral device to
provide an example heart rate sensor using simulated measurement data. The application
implements the "Sensor" role of the Heart Rate profile and the "Battery Reporter" role of the
Battery profile. The project is based on adopted profile and service specifications for Health Rate
([6] and [7]). The project also includes the Device Information Service ([12]).
The project can be opened with the following IAR workspace file:
C:\Texas Instruments\BLE-CC254x-1.3.2\Projects\ble\HeartRate\CC2540DB\heartrate.eww
4.1

Project Overview

The project structure is very similar to that of the SimpleBLEPeripheral project. The APP directory
contains the application source code and header files. The project contains one configuration,
CC2540DK-MINI Keyfob Slave, using the keyfob hardware platform.
4.1.1

User Interface

When not connected, the keyfob's right button is used to toggle advertising on and off. When in a
connection, the keyfob's left button cycles through different heart rate sensor data formats and the
right button sends a battery level-state notification.
4.1.2

Basic Operation

Power up the device and press the right button to enable advertising. From a heart rate collector
peer device, initiate a device discovery and connection procedure to discover and connect to the
heart rate sensor. The peer device should discover the heart rate service and configure it to
enable notifications of the heart rate measurement. The peer device may also discover and
configure the battery service for battery level-state notifications.
Once heart rate measurement notifications have been enabled the application will begin sending
data to the peer containing simulated measurement values. Pressing the left button cycles
through different data formats as follows:








Sensor contact not supported.
Sensor contact not detected.
Sensor contact and energy expended set.
Sensor contact and R-R Interval set.
Sensor contact, energy expended, and R-R Interval set.
Sensor contact, energy expended, R-R Interval, and UINT16 heart rate set.
Nothing set.

If the peer device initiates pairing then the devices will pair. Only "just works" pairing is supported
by the application (pairing without a passcode).
The application advertises using either a fast interval or a slow interval. When advertising is
initiated by a button press or when a connection is terminated due to link loss, the application will
start advertising at the fast interval for 30 seconds followed by the slow interval. When a
connection is terminated for any other reason the application will start advertising at the slow
interval. The advertising intervals and durations are configurable in file heartrate.c.
4.2

Software Description
Page 11 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

SWRU297 Version 1.3.2

The application is implemented in the file heartrate.c.
4.2.1

Initialization

The initialization of the application occurs in two phases: first, the HeartRate_Init function is
called by the OSAL. This function configures parameters in the peripheral profile, GAP, and GAP
bond manager. It also sets up the heart rate service and the battery service along with standard
GATT and GAP services in the attribute server. Then it sets an OSAL START_DEVICE_EVT
event. This triggers the second phase of the initialization, which can be found within the
HeartRate_ProcessEvent function. During this phase, the GAPRole_StartDevice function is
called to set up the GAP functions of the application. Then GAPBondMgr_Register is called to
register with the bond manager.
4.2.2

Event Processing

The application has two main event processing functions, HeartRate_ProcessEvent and
HeartRate_ProcessOSALMsg.
Function HeartRate_ProcessEvent handles events as follows:





SYS_EVENT_MSG: Service the OSAL queue and process OSAL messages.
START_DEVICE_EVT: Start the device, as described in the previous section.
HEART_PERIODIC_EVT: Send periodic heart rate measurements.
BATT_PERIODIC_EVT: Check the battery level and send notification if it changed.

Function HeartRate_ProcessOSALMsg handles OSAL messages as follows:

4.2.3

KEY_CHANGE messages: Call function HeartRate_HandleKeys to handle key presses.
Callbacks

The application callback functions are as follows:





4.2.4

HeartRateGapStateCB: This is the GAP event callback. It processes GAP events for
startup and link connect/disconnect.
HeartRateCB: This is the heart rate service callback. It handles enabling or disabling
periodic heart rate measurements when notifications of the heart rate measurement are
enabled or disabled.
HeartRateBattCB: This is the battery service callback. It handles enabling or disabling
periodic battery measurements when notifications of the battery level-state are enabled or
disabled.
Sending Notifications

The application sends notifications of the heart rate measurement and the battery level-state
when configured to do so by the peer device.
When the peer device configures the heart rate measurement for notification the application will
receive a heart rate service callback. The application starts a timer to begin periodic simulated
heart rate measurements. When the timer expires the application calls heartRateMeasNotify to
build and send a measurement using the heat rate service API.
When the peer device configures the battery level-state for notification the application will receive
a battery service callback. The application starts a timer to periodically measure the battery level.
When the timer expires the application calls battery service API function Batt_MeasLevel to
measure the battery level using the CC2450 ADC. Notification of the battery level-state is handled
inside the battery service; if the battery level has dropped since the previous measurement a
notification is sent.

5

Cycling Speed and Cadence (CSC) Sensor

This sample project implements the Cycling Speed and Cadence (CSC) profile in a BLE
peripheral device to provide a sample application of sensor that would be placed on a bicycle,
using simulated measurement data. The application implements the “Sensor” role of the Cycling
Page 12 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

SWRU297 Version 1.3.2

Speed and Cadence Profile. This profile also makes use of the optional Device Info Service,
which has default values that may be altered at compile or runtime to aid in identifying a specific
BLE device. This information is available in:
C:\Texas Instruments\BLE-CC254x-1.3.2\Projects\ble\Profiles\DevInfo\devinfoservice.c
The project can be opened with the following IAR workspace file:
C:\Texas Instruments\BLE-CC254x-1.3.2\Projects\ble\CyclingSensor\CC2541DB\CyclingSensor.eww

5.1
Project Overview
The project is very similar to the heart rate sensor project. The APP directory contains the
application source code and header files. The project contains two configurations:
 CC2541DK-MINI Keyfob Slave: using the keyfob hardware platform.
 CC2541: using the SmartRF platform.
5.1.1

User Interface

When not connected, the keyfob’s right button is used to toggle advertising on and off. When in a
connection, the keyfob’s left button cycles through different cycling speed and cadence sensor
data formats.
Holding both keys down for 5 seconds initiates a “soft reset.” This includes:
 Terminate all current connections
 Clearing all bond data
 Clearing white list of all peer addresses
5.1.2

Basic Operation

Power up the device and press the right button to enable advertising. From a CSC collector peer
device, initiate a device discovery and connection procedure to discover and connect to the
cycling sensor. The peer device should receive a slave security request and initiate a bond.
Once bonded, the collector should discover the CSC service and configure it to enable cycling
speed and cadence measurements.
Once CSC measurement notifications have been enabled the application will begin sending data
to the peer containing simulated measurement values. Pressing the left button cycles through
different data formats as follows:
 Sensor at rest (no speed or cadence detected).
 Sensor detecting speed but no cadence.
 Sensor detecting cadence but no speed.
 Sensor detecting speed and cadence.
The application advertises using either a fast interval or a slow interval. When advertising is
initiated by a button press or when a connection is terminated due to link loss, the application will
start advertising at the fast interval for 30 seconds. If the sensor has successfully bonded to a
peer device and stored the devices address in its white list, then for the for the first 10 seconds of
advertising the sensor will only attempt to connect to any device addresses stored in its white list.
After 10 seconds, the sensor will attempt to connect to any peer device that wishes to connect.
Independent of white list use, after 30 seconds of fast interval connection, a 30 second period of
slow interval advertising passes. After this, the device sleeps and waits for the right button to be
pressed before resuming advertising again.
If the device terminates connection for any other reason, the sensor will advertise for 60 seconds
at a slow interval and then sleep if no connection is made. It will begin advertising again only if
the right button is pressed.
5.2

Software Description
Page 13 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

SWRU297 Version 1.3.2

The application is implemented in the file cyclingSensor.c.
5.2.1

Initialization

Initialization of the application occurs in two phases: first, the CyclingSensor_Init function is
called by the OSAL. This function configures parameters in the peripheral profile, GAP, and GAP
bond manager. It also sets up the CSC service along with standard GATT and GAP services in
the attribute server. Then it sets an OSAL START_DEVICE_EVT event. This triggers the second
phase of the initialization, which can be found within the CyclingSensor_ProcessEvent function.
During this phase, the GAPRole_StartDevice function is called to set up the GAP functions of the
application. Then GAPBOND_Mgr_Register is called to register with the bond manager.
5.2.2

Event Processing

The application has two main event processing functions, CyclingSensor_ProcessEvent and
sensor_ProcessOSALMsg.
Function CyclingSensor_ProcessEvent handles events as follows:
 SYS_EVENT_MSG: Service the OSAL queue and process OSAL messages.
 START_DEVICE_EVT: Start the device, as described in the previous section.
 CSC_PERIODIC_EVT: Send periodic CSC measurements.
 CSC_CONN_PARAM_UPDATE_EVT: send parameter update until successful
 CSC_NEGLET_TIMEOUT_EVT: see section 5.2.8
 CSC_RESET_EVT: reset device as described above
Function cycling_ProcessOSALMsg handles OSAL messages as follows:

5.2.3

KEY_CHANGE message: Call function sensor_HandleKeys to handle key presses.

Callbacks

The application callback functions are as follows:



SensorGAPStateCB: This is the GAP event callback. It processes GAP events for
startup and link connect/disconnect.
SensorCB: This is the CSC service callback. It handles enabling or disabling periodic
CSC measurements when notifications of the CSC measurements are enabled or
disabled. Additionally, it informs the application when the peer device has updated a
sensor location or changed the cumulative distance traveled.

5.2.4

Sending Notifications

The application sends notifications of the CSC measurements when configured to do so by the
peer device. When the peer device configures the CSC measurements for notification the
application will receive a CSC service callback. The application starts a timer to begin periodic
simulated CSC measurements for a bicycle. When the timer expires the application calls
sensorMeasNotify to build and send a measurement using the CSC service API.
5.2.5

Confirming Indications

When the peer device writes to the sensors control point characteristic the peer device will
receive an indication in response. When the indication is received by the peer device, the device
must send an ATT_HandleValueConfirmation back to the server.
5.2.6

Reading from the Sensor

The CSC service has 2 readable characteristics: Features and Sensor Location. Sending a read
request to the Features characteristic triggers a response packet containing a byte array of the
feature capabilities of the sensor which are as follows:
 Wheel revolutions
 Crank revolutions
Page 14 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

SWRU297 Version 1.3.2

 Total distance
 Multiple sensor locations
Sending a read request to the Sensor Location characteristic triggers a response packet
containing the set position of the sensor on the bicycle. This value may be set by writing to the
control point (see below), requesting a sensor location update.
5.2.7

Writing to the Sensor

The CSC service has one writeable characteristic: the Control Point. A write request can be set
with the following requests:





CSC_SET_CUMM_VAL: Set the total distance traveled field.
CSC_START_SENS_CALIB: Calibrate the sensor. Not supported under current
profile spec, but it is required.
CSC_UPDATE_SENS_LOC: Update the location of the sensor.
CSC_REQ_SUPP_SENS_LOC: Request the list of supported sensor locations.

A response will be sent as an indication to the peer device after a write response it received. The
indication includes the CSC_COMMAND_RSP code, the requested operation code, and a code
indicating success or failure. If the command was a request for a list of valid sensor locations,
then the indication will also include a byte array containing the valid sensor locations.
5.2.8

Neglect Timer

This device has a compile time option that allows the sensor to terminate a connection if it sees
no user input for 15 seconds. In the context of this application, this means that after the device
has connected and notifications are disabled, the application starts a timer. This timer is restarted
whenever a read or write request comes from the peer device, and is disabled while notifications
are enabled. If the value USING_NEGLECT_TIMEOUT is set to FALSE at compile, then this
timer is permanently disabled at runtime.

6

Running Speed and Cadence (RSC) Sensor

This sample project implements the Running Speed and Cadence (RSC) profile in a BLE
peripheral device to provide a sample application of sensor that would be placed on a bicycle,
using simulated measurement data. The application implements the “Sensor” role of the Running
Speed and Cadence Profile. This profile also makes use of the optional Device Info Service in
the same manner as the Cycling Sensor.
The project can be opened with the following IAR workspace file:
C:\Texas Instruments\BLE-CC254x-1.3.2\Projects\ble\RunningSensor\CC2541DB\RunningSensor.eww

6.1
Project Overview
The project is very similar to the Cycling Sensor project. The APP directory contains the
application source code and header files. The project contains two configurations:
 CC2541DK-MINI Keyfob Slave: using the keyfob hardware platform.
 CC2541: using the SmartRF platform.
6.1.1

User Interface

When not connected, the keyfob’s right button is used to toggle advertising on and off. When in a
connection, the keyfob’s left button cycles through different running speed and cadence sensor
data formats.
Holding both keys down for 5 seconds initiates a “soft reset.” This includes:
 Terminate all current connections
 Clearing all bond data
 Clearing white list of all peer addresses
Page 15 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

6.1.2

SWRU297 Version 1.3.2

Basic Operation

Power up the device and press the right button to enable advertising. From a RSC collector peer
device, initiate a device discovery and connection procedure to discover and connect to the
cycling sensor. The peer device should receive a slave security request and initiate a bond.
Once bonded, the collector should discover the RSC service and configure it to enable running
speed and cadence measurements.
Once RSC measurement notifications have been enabled the application will begin sending data
to the peer containing simulated measurement values. Pressing the left button cycles through
different data formats as follows:
 At rest: neither instantaneous stride length nor total distance is included in measurement.
 Stride: instantaneous stride length is included in measurement.
 Distance: total distance is included in measurement.
 All: both stride length and total distance are included in measurement.
The application advertises using either a fast interval or a slow interval. When advertising is
initiated by a button press or when a connection is terminated due to link loss, the application will
start advertising at the fast interval for 30 seconds. If the sensor has successfully bonded to a
peer device and stored the devices address in its white list, then for the for the first 10 seconds of
advertising the sensor will only attempt to connect to any device addresses stored in its white list.
After 10 seconds, the sensor will attempt to connect to any peer device that wishes to connect.
Independent of white list use, after 30 seconds of fast interval connection, a 30 second period of
slow interval advertising passes. After this, the device sleeps and waits for the right button to be
pressed before resuming advertising again.
If the device terminates connection for any other reason, the sensor will advertise for 60 seconds
at a slow interval and then sleep if no connection is made. It will begin advertising again only if
the right button is pressed.
6.2
Software Description
The application is implemented in the file runningSensor.c.
6.2.1

Initialization

Initialization of the application occurs in two phases: first, the RunningSensor_Init function is
called by the OSAL. This function configures parameters in the peripheral profile, GAP, and GAP
bond manager. It also sets up the RSC service along with standard GATT and GAP services in
the attribute server. Then it sets an OSAL START_DEVICE_EVT event. This triggers the second
phase of the initialization, which can be found within the RunningSensor_ProcessEvent
function. During this phase, the GAPRole_StartDevice function is called to set up the GAP
functions of the application. Then GAPBOND_Mgr_Register is called to register with the bond
manager.
6.2.2

Event Processing

The application has two main event processing functions, RunningSensor_ProcessEvent and
sensor_ProcessOSALMsg.
Function RunningSensor_ProcessEvent handles events as follows:
 SYS_EVENT_MSG: Service the OSAL queue and process OSAL messages.
 START_DEVICE_EVT: Start the device, as described in the previous section.
 RSC_PERIODIC_EVT: Send periodic CSC measurements.
 RSC_CONN_PARAM_UPDATE_EVT: send parameter update until successful
 RSC_NEGLECT_TIMEOUT_EVT: see section 6.2.8
 RSC_RESET_EVT: reset device as described above
Page 16 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

SWRU297 Version 1.3.2

Function cycling_ProcessOSALMsg handles OSAL messages as follows:

6.2.3

KEY_CHANGE message: Call function sensor_HandleKeys to handle key presses.

Callbacks

The application callback functions are as follows:



SensorGAPStateCB: This is the GAP event callback. It processes GAP events for
startup and link connect/disconnect.
SensorCB: This is the RSC service callback. It handles enabling or disabling periodic
RSC measurements when notifications of the RSC measurements are enabled or
disabled. Additionally, it informs the application when the peer device has updated a
sensor location or changed the cumulative distance traveled.

6.2.4

Sending Notifications

The application sends notifications of the RSC measurements when configured to do so by the
peer device. When the peer device configures the RSC measurements for notification the
application will receive a RSC service callback. The application starts a timer to begin periodic
simulated RSC measurements for a bicycle. When the timer expires the application calls
sensorMeasNotify to build and send a measurement using the RSC service API.
6.2.5

Confirming Indications

When the peer device writes to the sensors control point characteristic the peer device will
receive an indication in response. When the indication is received by the peer device, the device
must send an ATT_HandleValueConfirmation back to the server.
6.2.6

Reading from the Sensor

The RSC service has 2 readable characteristics: Features and Sensor Location. Sending a read
request to the Features characteristic triggers a response packet containing a byte array of the
feature capabilities of the sensor which are as follows:
 Instantaneous Stride Length
 Walking or Running Status
 Total distance
 Multiple sensor locations
 Sensor Calibration Procedure Supported
Sending a read request to the Sensor Location characteristic triggers a response packet
containing the set position of the sensor on the body. This value may be set by writing to the
control point (see below), requesting a sensor location update.
6.2.7

Writing to the Sensor

The CSC service has one writeable characteristic: the Control Point. A write request can be set
with the following requests:





RSC_SET_CUMM_VAL: Set the total distance traveled field.
RSC_START_SENS_CALIB: Calibrate the sensor. Not supported under current
profile spec, but it is required.
RSC_UPDATE_SENS_LOC: Update the location of the sensor.
RSC_REQ_SUPP_SENS_LOC: Request the list of supported sensor locations.

A response will be sent as an indication to the peer device after a write response it received. The
indication includes the RSC_COMMAND_RSP code, the requested operation code, and a code
indicating success or failure. If the command was a request for a list of valid sensor locations,
then the indication will also include a byte array containing the valid sensor locations.

Page 17 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

6.2.8

SWRU297 Version 1.3.2

Neglect Timer

This device has a compile time option that allows the sensor to terminate a connection if it sees
no user input for 15 seconds. In the context of this application, this means that after the device
has connected and notifications are disabled, the application starts a timer. This timer is restarted
whenever a read or write request comes from the peer device, and is disabled while notifications
are enabled. If the value USING_NEGLECT_TIMEOUT is set to FALSE at compile, then this
timer is permanently disabled at runtime.

7

Glucose Collector

This sample project implements a Glucose Collector. The application is designed to connect to
the glucose sensor sample application to demonstrate the operation of the Glucose Profile.
7.1

Project Overview

The Glucose Collector project structure is very similar to that of the SimpleBLECentral project.
The APP directory contains the application source code and header files. The project contains
one configuration, CC2540EM Master, using the SmartRF05EB + CC2540EM hardware platform.
7.1.1

User Interface

The SmartRF05EB joystick and display provide a user interface for the application. The joystick
and buttons are used as follows:






Joystick Up: If not connected, start or stop device discovery. If connected to a glucose
sensor, request the number of records that meet configured filter criteria.
Joystick Left: Scroll through device discovery results. If connected to a glucose sensor,
send a record access abort message.
Joystick Center: Connect or disconnect to/from the currently selected device.
Joystick Right: If connected, request records that meet configured filter criteria.
Joystick Down: If connected, clear records that meet configured filter criteria. If not
connected, erase all bonds.

The LCD display is used to display the following information:







7.1.2

Device BD address.
Device discovery results.
Connection state.
Pairing and bonding status.
Number of records requested.
Sequence number, glucose concentration, and Hba1c value of received glucose
measurement and context notifications.
Basic Operation

When the application powers up it displays "Gluc. Collector" and the BD address of the device.
Press Joystick Up to start device discovery. When discovery completes the number of devices
found will be displayed. Press Joystick Left to scroll through the devices.
To connect to the selected device press Joystick Center. The connection status will be displayed.
Once connected, the application will attempt to discover the Glucose service and Device
Information service on the peer device. Since the Glucose profile required security the application
will also initiate bonding. When the bonding is complete, other operations such as reading or
erasing records can be performed described in the previous section. It is important to note that,
due to the input / output capabilities of the keyfob, we have to use a fixed password in order to
achieve authenticated pairing. We have set the I/O capabilities of the keyfob to display only. The
idea is that the keyfob will display the passcode and it will be entered on the SmartRF. However,
because the keyfob and SmartRF don’t actually have these I/O capabilities, we hard code the
passcode in the sensor and collector projects to be 19655.
Page 18 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

To disconnect press Joystick Center again.
Joystick Center again.
7.1.3

SWRU297 Version 1.3.2

To reconnect to the same device again press

Record Filter Configuration

Glucose record requests use filters to select the records that will be operated on by the request.
These filters are configured in the collector using compile time configuration.
In file glucoseCollector.c, macro GLUCOSE_FILTER_ENABLED controls whether filters are used.
When set to FALSE, operations that read, erase, or get the number of records will operate on all
records. When set to TRUE, these operations will use either a time filter or sequence number
filter,
as
configured
in
macro
DEFAULT_FILTER_TYPE.
When
set
to
CTL_PNT_FILTER_SEQNUM the collector will filter on sequence number. When set to
CTL_PNT_FILTER_TIME the collector will filter on time.
File glucoseCollector.c has hardcoded time and sequence number filter values. These are set in
variables filterTime1, filterTime2, filterSeqNum1, and filterSeqNum2.
7.2

Software Description

The application is implemented in the following files:


glucoseCollector.c: Main initialization, event handling and callback functions.



glucose_config.c: Characteristic configuration functions.



glucose_discovery.c: Service discovery functions.



glucose_ind.c: Indication and notification handling functions.



glucose_ctlpnt.c: Record access control point functions.

7.2.1

Initialization

The initialization of the application occurs in two phases: first, the GlucColl_Init function is called
by the OSAL. This function configures parameters in the central profile, GAP, and GAP bond
manager and also initializes GATT for client operation. It also sets up standard GATT and GAP
services in the attribute server. Then it sets an OSAL START_DEVICE_EVT event. This triggers
the second phase of the initialization, which can be found within the GlucColl_ProcessEvent
function. During this phase, the GAPCentralRole_StartDevice function is called to set up the
GAP functions of the application. Then GAPBondMgr_Register is called to register with the
bond manager.
7.2.2

Event Processing

The application has two main event processing functions, GlucColl_ProcessEvent and
GlucColl_ProcessOSALMsg.
Function GlucColl_ProcessEvent handles events as follows:


SYS_EVENT_MSG: Service the OSAL queue and process OSAL messages.



START_DEVICE_EVT: Start the device, as described in the previous section.



START_DISCOVERY_EVT: Start service discovery.



PROCEDURE_TIMEOUT_EVT: A glucose record access procedure has timed out.

Function GlucColl_ProcessOSALMsg handles OSAL messages as follows:


KEY_CHANGE messages: Call function GlucColl_HandleKeys to handle keypresses.



GATT_MSG_EVENT messages:
messages from GATT.

7.2.3

Call function GlucCollProcessGATTMsg to handle

Callbacks

The application callback functions are as follows:


GlucCollCentralEventCB: This is the GAP event callback. It processes GAP events for
initialization, device discovery, and link connect/disconnect.
Page 19 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

SWRU297 Version 1.3.2



GlucCollPairStateCB: This is the GAP bond manager state callback. It displays the
status of pairing and bonding operations.



GlucCollPasscodeCB: This is the GAP bond manager passcode callback. It generates
and displays a passcode.

7.2.4

Service Discovery

The GlucColl application performs service discovery for the Glucose service and Device
Information service. Discovery is initiated when a connection is established by setting OSAL
event START_DISCOVERY_EVT.
This will result in execution of function
GlucCollCentralStartDiscovery, which performs primary service discovery for the Glucose
service and Device ID service. When GATT events are received during service discovery
function glucCollProcessGATTMsg is called. This function processes the results of the previous
GATT procedure and initiates the next step in the discovery process.
7.2.5

Service Configuration

When service discovery completes the service configuration procedure is initiated.
procedure reads and writes characteristics of interest in the discovered services.

This

The main service configuration function is glucoseConfigNext. This function searches the
cached handle array for the next characteristic of interest and performs a read or write on that
characteristic.
When a GATT read or write response is received, function glucoseConfigGattMsg is called.
This function processes the received response and performs an action, such as updating the
clock display, and then calls glucoseConfigNext to initiate the next read or write.
The application writes all discovered client characteristic configuration descriptors to enable
notification or indication. The application also reads some characteristics and then performs no
action with the received response. This is done simply for testing and demonstration.
7.2.6

Record Access Control Point

The Glucose profile uses a characteristic called the record access control point to perform
operations on glucose measurement records stored by the glucose sensor. File glucose_ctlpnt.c
contains functions for sending control point messages. The following different operations can be
performed:





Retrieve stored records.
Delete stored records.
Abort an operation in progress.
Report number of stored records.

The collector sends control point messages to a sensor by using write requests, while the sensor
sends control point messages to the collector by using indications. When records are retrieved,
the glucose measurement and glucose context are sent via notifications on their respective
characteristics.
If an expected response is not received, the operation will time out after 30 seconds and the
collector will close the connection.

8

Glucose Sensor

This sample project implements the Glucose profile in a BLE peripheral device to provide an
example glucose sensor using simulated measurement data. The application implements the
"Sensor" role of the Glucose Profile.
8.1

Project Overview

The project structure is very similar to that of the SimpleBLEPeripheral project. The APP
directory contains the application source code and header files. The project contains one
configuration, CC2540DK-MINI Keyfob Slave, using the keyfob hardware platform.
8.1.1

User Interface
Page 20 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

SWRU297 Version 1.3.2

When not connected, the keyfob's right button is used to toggle advertising on and off. When in a
connection, the keyfob's left button sends a glucose measurement and glucose context.
8.1.2

Basic Operation

Power up the device and press the right button to enable advertising. From a glucose collector
peer device, initiate a device discovery and connection procedure to discover and connect to the
glucose sensor. The peer device should discover the glucose service and configure it to enable
notifications of the glucose measurement. It may also enable notifications of the glucose
measurement context.
Once glucose measurement notifications have been enabled a simulated measurement can be
sent by pressing the left button. If the peer device has also enabled notifications of the glucose
measurement context then this will be sent following the glucose measurement.
The peer device may also write commands to the record access control point to retrieve or erase
stored glucose measurement records. The sensor has four hardcoded simulated records.
If the peer device initiates pairing then the devices will pair. Only "just works" pairing is supported
by the application (pairing without a passcode).
8.2

Software Description

The application is implemented in the file glucose.c.
8.2.1

Initialization

The initialization of the application occurs in two phases: first, the Glucose_Init function is called
by the OSAL. This function configures parameters in the peripheral profile, GAP, and GAP bond
manager. It also sets up the glucose service along with standard GATT and GAP services in the
attribute server. Then it sets an OSAL START_DEVICE_EVT event. This triggers the second
phase of the initialization, which can be found within the Glucose_ProcessEvent function. During
this phase, the GAPRole_StartDevice function is called to set up the GAP functions of the
application. Then GAPBondMgr_Register is called to register with the bond manager.
8.2.2

Event Processing

The application has two main event processing functions, Glucose_ProcessEvent and
Glucose_ProcessOSALMsg.
Function Glucose_ProcessEvent handles events as follows:




SYS_EVENT_MSG: Service the OSAL queue and process OSAL messages.
START_DEVICE_EVT: Start the device, as described in the previous section.

Function Glucose_ProcessOSALMsg handles OSAL messages as follows:




8.2.3

KEY_CHANGE messages: Call function Glucose_HandleKeys to handle
keypresses.
CTL_PNT_MSG: Call function glucoseProcessCtlPntMsg to process record
access control point messages.
Callbacks

The application callback functions are as follows:




glucoseGapStateCB: This is the GAP event callback. It processes GAP events
for startup and link connect/disconnect.
glucosePairStateCB: This is the GAP pairing state callback. It is used to store
the bonding state of pairing.

Page 21 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2



8.2.4

SWRU297 Version 1.3.2

GlucoseCB: This is the glucose service callback. It handles enabling or
disabling of indications of the glucose measurement, context, glucose
measurement context, and record access control point.
Sending Notifications and Indications

The application sends notifications of the glucose measurement and glucose measurement
context when configured to do so by the peer device. The application sends indications of the
record access control point when configured to do so by the peer device.
Transmissions of notifications are paced by using a timer to trigger the next transmission. The
period of the timer is set in macro DEFAULT_NOTI_PERIOD.
8.2.5

Record Access Control Point Processing

The record access control point is used to perform retrieval and management of measurements
stored in the glucose sensor. The record access control point has its own protocol to perform
these
functions.
The
application
implements
this
protocol
in
function
glucoseProcessCtlPntMsg. This function is executed when the peer device writes a message
to the control point.
Function glucoseProcessCtlPntMsg processes received messages by decoding the message
operation and operands. It then executes function glucoseCtlPntHandleOpcode to perform the
detailed processing required by the operation.
A set of example utility functions is implemented that processes the simulated glucose
measurement data. These utility functions perform operations such as:




9

Find records earlier than or later than a given time and date.
Find records within a range of two given times and dates.
Find first, last, or all records.

HID Advanced Remote Control

The HID Advanced Remote Control is a sample application which implements a HID mouse,
keyboard, and consumer controls. A gyro and accelerometer act as inputs allow the user to move
a mouse by simply pointing the remote. The example is HID compliant and has been tested with
Windows8 for example. For more information, refer to the TI_CC2541_ARC_User_Guide included
with this release.
The example applications for both peripheral and HID Dongle are located at
C:\TexasInstruments\BLE-CC254x-1.3.2\Projects\ble\HIDAdvRemote\ HIDAdvRemote.eww
C:\TexasInstruments\BLE-CC254x-1.3.2\Projects\ble\HIDAdvRemoteDongle\
HIDAdvRemoteDongle.eww

10 HID Emulated Keyboard
This sample project implements the HID Over GATT profile in a BLE peripheral device to provide
an example of how a HID keyboard can be emulated with a simple two button remote control
device. The project is based on adopted profile and service specifications for HID over GATT ([8]
and [9]) and Scan Parameters ([10] and [11]). The project also includes the Device Information
Service ([12]) and Battery Service ([13]).
The project can be opened with the following IAR workspace file:
C:\TexasInstruments\BLE-CC254x-1.3.2\Projects\ble\HIDEmuKbd\CC2540DB\ HidEmuKbd.eww
10.1

Project Overview

The project structure is very similar to that of the SimpleBLEPeripheral project.
directory contains the application source code and header files.

The APP

Page 22 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

SWRU297 Version 1.3.2

The project contains one configuration, CC2540DK-MINI Keyfob Slave, using the keyfob
hardware platform.
10.1.1 User Interface
When not connected and not already advertising, pressing either button will initiate advertising.
When in a connection, the keyfob's left button sends a “left arrow” key and the right button sends
a “right arrow” key.
Note that a secure connection must be established before key presses will be sent to the peer
device.
10.1.2 Basic Operation
Power up the device and press either button to enable advertising. From a HID Host peer device,
initiate a device discovery and connection procedure to discover and connect to the HID device.
The peer device should discover the HID service and recognize the device as a keyboard. The
peer device may also discover and configure the battery service for battery level-state
notifications.
By default the HID device requires security and uses “just works” pairing. After a secure
connection is established and the HID host configures the HID service to enable notifications, the
HID device can send HID key presses to the HID host. A notification is sent when a button is
pressed and when a button is released.
The HID host can send keyboard LED information to the device to illuminate the keyfob LEDs.
The “caps lock” setting controls the green LED and the “num lock” setting controls the red LED.
If there is no HID activity for a period of time (20 seconds by default) the HID device will
disconnect. When the connection is closed the HID device will not advertise. Press either button
to enable advertising and connect again.
10.2

Software Description

The project uses the following services and profiles:






10.3

Battery service (battservice.c and battservice.h).
Device Information service (devinfoservice.c and devinfoservice.h).
Scan Parameters service (scanparamservice.c and scanparamservice.h).
HID service for keyboard (hidkbdservice.c hidkbdservice.h).
HID device profile (hiddev.c and hiddev.h). This is a common profile for HID devices that
performs the following procedures:
o Advertising, connection procedures, and security procedures.
o Sending HID notifications.
o Handling read and write of HID service characteristics.
HidEmuKbd Application

The application is implemented in the file hidemukbd.c.
10.3.1 Initialization
The HidEmuKbd_Init function is called by the OSAL to perform task initialization procedures.
This function sets parameters for the peripheral profile, GAP bond manager, and Battery service.
The function also registers the HID keyboard service and HID device profile.
10.3.2 Event Processing
The application has two main event processing functions, HidEmuKbd_ProcessEvent and
HidEmuKbd_ProcessOSALMsg.
Function HidEmuKbd_ProcessEvent handles the SYS_EVENT_MSG event, which services the
OSAL queue and processes OSAL messages.
Page 23 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

SWRU297 Version 1.3.2

Function HidEmuKbd_ProcessOSALMsg handles OSAL messages as follows:


KEY_CHANGE messages: Call function HidEmuKbd_HandleKeys to handle
keypresses.

10.3.3 Callbacks
The application callback functions are as follows:



hidEmuKbdRptCB: This is the HID device report callback. It processes HID reports
received from the HID host.
hidEmuKbdEvtCB: This is the HID device event callback. It handles HID events, such
as enter/exit suspend or enter/exit boot mode.

10.3.4 Sending Notifications
The application sends notifications containing HID keypress data when a button is pressed. This
is done in function HidEmuKbd_HandleKeys by calling HID device profile function
HidDev_Report. The details of sending notifications are handled in the HID device profile.
10.4

HID Device Profile

The HID device profile is implemented in the file hiddev.c.
10.4.1 Initialization
The initialization of occurs in two phases: first, the HidDev_Init function is called by OSAL. This
function sets up the battery, device information, and scan parameters services along with
standard GATT and GAP services in the attribute server. Then it sets an OSAL
START_DEVICE_EVT event. This triggers the second phase of the initialization, which can be
found within the HidDev_ProcessEvent function. During this phase, the GAPRole_StartDevice
function is called to set up the GAP functions of the application. Then GAPBondMgr_Register is
called to register with the bond manager.
10.4.2 Event Processing
The application has two main event processing functions, HidDev_ProcessEvent and
HidDev_ProcessOSALMsg.
Function HidDev_ProcessEvent handles events as follows:





SYS_EVENT_MSG: Service the OSAL queue and process OSAL messages.
START_DEVICE_EVT: Start the device, as described in the previous section.
HID_IDLE_EVT: Terminate the connection if idle.
BATT_PERIODIC_EVT: Check the battery level and send notification if it changed.

Function HidDev_ProcessOSALMsg handles OSAL messages as follows:


GATT_MSG_EVENT messages: Call function hidDevProcessGattMsg to process
GATT messages.

10.4.3 Callbacks
The HID device profile callback functions are as follows:





HidDevGapStateCB: This is the GAP event callback. It processes GAP events for
startup and link connect/disconnect.
hidDevPairStateCB: This is the pairing state callback. Handle pairing events.
hidDevPasscodeCB: This is the passcode callback. Send a passcode response.
HidDevBattCB: This is the battery service callback. It handles enabling or disabling
periodic battery measurements when notifications of the battery level-state are enabled or
disabled.
Page 24 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2



SWRU297 Version 1.3.2

hidDevScanParamCB: This is the scan parameters service callback. Handle a scan
parameters service event.

10.4.4 GATT Read and Write Callbacks
The HID device profile GATT read and write callbacks, HidDev_WriteAttrCB and
HidDev_ReadAttrCB handle reading and writing of all HID characteristics. These functions are
used by a HID service when registering the service with GATT.
10.4.5

Mapping HID Reports to HID Characteristics

A HID service defines one or more HID reports in its service that are used to send and receive
HID data. The HID device profile has a table that maps HID reports to HID characteristics. The
table is constructed by the HID service using the HID device profile and must be registered with
the HID device profile by calling function HidDev_RegisterReports.
10.4.6 Sending and Receiving HID Reports
The application calls function HidDev_Report to send a HID report. The HID device sends HID
report notifications to the HID host when configured to do so. When notifications are enabled or
disabled for a HID report characteristic the HID report callback is executed with event
HID_DEV_OPER_ENABLE or HID_DEV_OPER_DISABLE.
A HID report is received from the HID host is either a read event or write event. The HID report
callback is executed with event HID_DEV_OPER_READ or HID_DEV_OPER_WRITE.
10.4.7 Advertising and Connection Procedures
The HID device profile manages advertising and connection procedures. The device will start
advertising if the HidDev_Report function is called when not connected and not already
advertising.
Advertising is performed at an “initial” rate when not bonded, and at a “low” or “high” rate if
bonded. The advertising intervals and durations for the different rates are configurable.
If the device is bonded the device will advertise at the high rate when reconnecting to send a HID
report. If the connection is terminated and the device is bonded and the flags are set to
HID_FLAGS_NORMALLY_CONNECTABLE the device will advertise at the low rate. Otherwise
the device will not advertise when disconnected until it has data to send.
If no HID data is sent or received within an idle timeout period the HID device profile will terminate
the connection, unless pairing is in progress. The idle timeout is configured by the application
and can be disabled by setting it to zero.

11 HostTestRelease- BLE Network Processor
The HostTestRelease project implements a BLE network processor, for use with an external
microcontroller or a PC software application such as BTool. More information on the
HostTestRelease project can be found in [1].

12 KeyFobDemo
The KeyFobDemo application will demonstrate the following.





Report battery level
Report 3 axis accelerometer readings.
Report proximity changes
Report key press changes

The following GATT services are used:


Device Information (see [12])
Page 25 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2








SWRU297 Version 1.3.2

Link Loss (for Proximity Profile, Reporter role; see [14] and [16])
Immediate Alert (for Proximity Profile, Reporter role and Find Me Profile, Target role; see
[14], [15], and [17])
Tx Power (for Proximity Profile, Reporter role; see [18])
Battery (see [13])
Accelerometer
SimpleKeys

The accelerometer and simple keys profiles are not aligned to official SIG profiles, but rather
serve as an example of profile service implementation. The device information service and
proximity-related services are based on adopted specifications.
12.1

Project Overview

The project structure is very similar to that of the SimpleBLEPeripheral project. The APP directory
contains the application source code and header files. The project supports the following
configurations.
-

CC2540DK-MINI Keyfob Slave: using the keyfob hardware platform.

12.1.1 User Interface
There are two button inputs for this application, an LED, and buzzer.
Right Button
When not connected, this button is used to toggle advertising on and off. When in a connection,
this will register a key press which may be enabled to notify a peer device or may be read by a
peer device.
Left Button
When in a connection, this will register a key press which may be enabled to notify a peer device
or may be read by a peer device.
LED
Flash when Link Loss Alert is triggered.
Buzzer
The buzzer turns on if a Link Loss Alert is triggered.
12.1.2 Battery Operation
They KeyFob used an ADC to read remaining battery level. The battery profile allows for the USB
Dongle to read the percentage of battery remaining on the keyfob by reading the value of <
BATTERY_LEVEL_UUID>
12.1.3 Accelerometer Operation
The keyfob uses SPI to interface to a 3 axis accelerometer on the KeyFobDemo. The
accelerometer must be enabled < ACCEL_ENABLER_UUID> by writing a value of “01”. Once the
accelerometer is enabled, each axis can be configured to send notifications by writing “01 00” to
the characteristic configuration for each axis < GATT_CLIENT_CHAR_CFG_UUID>. In addition,
the values can be read by reading , ,.
12.1.4 Keys
The simple keys service on the keyfob allows the device to send notifications of key presses and
releases to a central device. The application registers with HAL to receive a callback in case HAL
detects a key change.
The peer device may read the value of the keys by reading .
The peer device may enable key
.

press

notifications

by

writing

a

“01”

to

Page 26 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

SWRU297 Version 1.3.2

A value of “00” indicates that neither key is pressed. A value of “01” indicates that the left key is
pressed. A value of “02” indicates that the right key is pressed. A value of “03” indicates that both
keys are pressed.
12.1.5 Proximity
One of the services of the proximity profile is the link loss service, which allows the proximity
reporter to begin an alert in the event the connection drops.
The link loss alert can be set by writing a value to .
The default alert value setting is “00”, which indicates “no alert.” To turn on the alert, write a 1byte value of “01” (low alert) or “02” (high alert). By default, the link does not timeout until 20
seconds have gone by without receiving a packet. This “Supervision Timeout” value can be
changed in the “Connection Services” tab; however the timeout value must be set before the
connection is established. After completing the write, move the keyfob device far enough away
from the USB Dongle until the link drops. Alternatively, you can disconnect the USB Dongle from
the PC, effectively dropping the connection. Once the timeout on the keyfob expires, the alarm
will be triggered. If a low alet was set, the keyfob will make a low pitched beep. If a high alert was
set, the keyfob will make a high pitched beep and the LED will blink. In either case, the keyfob will
beep ten times and then stop. Alternatively to stop the beeping, either a new connection can be
formed with the keyfob, or the button can be pressed.
12.2

Software Description

The application is implemented in the file keyFobDemo.c.
12.2.1 Initialization
The initialization of the application occurs in two phases: first, the KeyFobApp_Init function is
called by the OSAL. This function configures parameters in the peripheral profile, GAP, and GAP
bond manager. It also sets up the KeyFobDemo example services along with standard GATT and
GAP services in the attribute server. Then it sets an OSAL START_DEVICE_EVT event. This
triggers the second phase of the initialization, which can be found within the
KeyFobApp_ProcessEvent function. During this phase, the GAPRole_StartDevice function is
called to set up the GAP functions of the application. Then GAPBondMgr_Register is called to
register with the bond manager.
12.2.2 Event Processing
The application has two main event processing functions, KeyFobApp_ProcessEvent and
KeyFobApp_ProcessOSALMsg.
Function KeyFobApp_ProcessEvent handles events as follows:






SYS_EVENT_MSG: Service the OSAL queue and process OSAL messages.
KFD_START_DEVICE_EVT: Start the device, as described in the previous section.
KFD_ACCEL_READ_EVT: Read accelerometer and set timer for periodic reads.
KFD_BATTERY_CHECK_EVT: Read battery level and set timer for periodic reads.
KFD_TOGGLE_BUZZER_EVT: Toggle buzzer on proximity state.

Function KeyFobApp_ProcessOSALMsg handles OSAL messages as follows:


KEY_CHANGE: Handle key presses.

12.2.3 Callbacks
The application callback functions are as follows:




PeripheralStateNotificationCB: This is the GAP event callback. It processes GAP
events for startup and link connect/disconnect.
ProximityAttrCB: Receive info on link loss and setup from proximity service.
AccelEnablerChangeCB: Handle enabling of accelerometer.

Page 27 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

SWRU297 Version 1.3.2

13 SensorTag
The SensorTag is a BLE peripheral slave device which runs on the CC2541 SensorTag
hardware platform. The Sensor Tag includes five peripheral sensors with a complete software
solution for sensor drivers interfaced to a GATT server running on TI BLE stack. The GATT server
contains a primary service for each sensor for configuration and data collection.
13.1 Operation
On startup, the SensorTag is advertising with a 100ms interval. The connection is established by
a Central Device and the sensors can then be configured to provide measurement data. The
Central Device could be any BLE compliant device and the main focus is on BLE compliant
mobile phones, running either Andriod or iOS. The central device should be able to





Scan and discover the Sensor Tag. (Scan response contain name “SensorTag”)
Establish connection based on user defined Connection Parameters
Perform Service Discovery – Discover Characteristic by UUID
Operate as a GATT Client - Write to and read from Characteristic Value

The Central Device shall initiate the connection and thereby become the Master.
To obtain the data, the corresponding sensor must first be activated, which is done via a
Characteristic Value write to appropriate service.
The most power efficient way to obtain measurements for a sensor is to




Enable notification
Enable Sensor
When notification with data is obtained at the Master side, disable the sensor (notification
still on though)

Alternative do not use notifications at all, then simply




Enable sensor
Read data and verify
Disable sensor

For the latter alternative please keep in mind that sensor take different amount of time to perform
measurement. Depending on the connection interval (~10 – 4000 ms) set by the Central Device,
the time for achieving measurement data can vary. The individual sensors require varying delays
to complete measurements. Recommended setting is 100ms but for fast accelerometer and
Magnetometer data updates, a lower is necessary. Notifications can be stopped and the sensors
turned on/off
13.2 Sensors
The SensorTag has support for the following sensors:







IR Temperature, both object and ambient temperature
Accelerometer, 3 axis
Humidity, both relative humidity and temperature
Magnetometer, 3 axis
Barometer, both pressure and temperature
Gyroscope, 3 axis

14 SimpleBLECentral
The SimpleBLECentral project implements a very simple BLE central device with GATT client
functionality. It makes use of the SmartRF05 + CC2540EM hardware platform. This project can be
used as a framework for developing many different central-role applications. More information on
the SimpleBLECentral project can be found in [1].
Page 28 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

SWRU297 Version 1.3.2

15 SimpleBLEPeripheral
The SimpleBLEPeripheral project implements a very simple BLE peripheral device with GATT
services, including configurations for the CC2540DK-MINI keyfob as well as the SmartRF05 +
CC2540EM hardware platforms. This project can be used as a framework for developing many
different peripheral-role applications. More information on the SimpleBLEPeripheral project can
be found in [1].

16 TimeApp- BLE Watch
This sample project implements time and alert-related profiles in a BLE peripheral device to
provide an example of how Bluetooth LE profiles are used in a product like a watch. The project is
based on adopted profile specifications for Time ([19]), Alert Notification ([20]), and Phone Alert
Status ([21]). All profiles are implemented in the Client role. In addition, the following Network
Availability Profile, Network Monitor role has been implemented, based on Network Availability
Draft Specification d05r04 (UCRDD).
The project can be opened with the following IAR workspace file:
C:\Texas Instruments\BLE-CC254x-1.3.2\Projects\ble\TimeApp\CC2540\TimeApp.eww
16.1

Project Overview

The TimeApp project structure is very similar to that of the SimpleBLEPeripheral project. The APP
directory contains the application source code and header files. The project contains one
configuration, CC2540EM Slave, using the SmartRF05EB + CC2540EM hardware platform.
16.1.1 User Interface
The SmartRF05EB joystick and display provide a user interface for the application. The joystick
and buttons are used as follows:






Joystick Up: Start or stop advertising.
Joystick Left: If connected, send a command to the Alert Notification control point.
Joystick Center: If connected, disconnect. If held down on power-up, erase all bonds.
Joystick Right: If connected, initiate a Reference Time update.
Joystick Down: If connected, initiates a Ringer Control Point update

The LCD display is used to display the following information:











Device BD address.
Connection state.
Pairing and bonding status.
Passcode display.
Time and date.
Network availability.
Battery state of peer device.
Alert notification messages.
Unread message alerts.
Ringer status.

16.1.2 Basic Operation
When the application powers up it displays "Time App", the BD address of the device, and a
default time and date of "00:00 Jan01 2000". To connect, press Joystick Up to start advertising
then initiate a connection from a peer device. The connection status will be displayed. Once
connected, the application will attempt to discover the following services on the peer device:





Current Time Service
DST Change Service
Reference Time Service
Alert Notification Service
Page 29 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2





SWRU297 Version 1.3.2

Phone Alert Status Service
Network Availability Service
Battery Service

The discovery procedure will cache handles of interest. When bonded to a peer device, the
handles are saved so that the discovery procedure is not performed on subsequent connections.
If a service is discovered certain service characteristics are read and displayed. The network
availability status and battery level will be displayed and the current time will be updated.
The application also enables notification or indication for characteristics that support these
operations. This allows the peer device to send notifications or indications updating the time,
network availability, or battery status. The peer device can also send alert notification messages
and unread message alerts. These updates and messages will be displayed on the LCD.
The peer device may initiate pairing. If a passcode is required the application will generate and
display a random passcode. Enter this passcode on the peer device to proceed with pairing.
The application advertises using either a fast interval or a slow interval. When advertising is
initiated by a button press or when a connection is terminated due to link loss, the application will
start advertising at the fast interval for 30 seconds followed by the slow interval. When a
connection is terminated for any other reason the application will start advertising at the slow
interval. The advertising intervals and durations are configurable in file timeapp.c.
16.2

Software Description

The TimeApp application is implemented in the following files:






timeapp.c: Main initialization, event handling and callback functions.
timeapp_clock.c: Clock timekeeping and display functions.
timeapp_config.c: Characteristic configuration functions.
timeapp_discovery.c: Service discovery functions.
timeapp_ind.c: Indication and notification handling functions.

16.2.1 Initialization
The initialization of the application occurs in two phases: first, the TimeApp_Init function is called
by the OSAL. This function configures parameters in the peripheral profile, GAP, and GAP bond
manager and also initializes GATT for client operation. It also sets up standard GATT and GAP
services in the attribute server. Then it sets an OSAL START_DEVICE_EVT event. This triggers
the second phase of the initialization, which can be found within the TimeApp_ProcessEvent
function. During this phase, the GAPRole_StartDevice function is called to set up the GAP
functions of the application. Then GAPBondMgr_Register is called to register with the bond
manager.
16.2.2 Event Processing
The application has two main event processing functions, TimeApp_ProcessEvent and
timeApp_ProcessOSALMsg.
Function TimeApp_ProcessEvent handles events as follows:





SYS_EVENT_MSG: Service the OSAL queue and process OSAL messages.
START_DEVICE_EVT: Start the device, as described in the previous section.
START_DISCOVERY_EVT: Start service discovery.
CLOCK_UPDATE_EVT: Update the clock display.

Function timeApp_ProcessOSALMsg handles OSAL messages as follows:



KEY_CHANGE messages: Call function timeApp_HandleKeys to handle keypresses.
GATT_MSG_EVENT messages: Call function timeAppProcessGATTMsg to handle
messages from GATT.

Page 30 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

SWRU297 Version 1.3.2

16.2.3 Callbacks
The application callback functions are as follows:




timeAppGapStateCB: This is the GAP event callback. It processes GAP events for
startup and link connect/disconnect.
timeAppPairStateCB: This is the GAP bond manager state callback. It displays the
status of pairing and bonding operations.
timeAppPasscodeCB: This is the GAP bond manager passcode callback. It generates
and displays a passcode.

16.2.4 Service Discovery
The application performs service discovery for several Bluetooth LE services. Discovery is
initiated when a connection is established to a peer device with which there is no existing bond.
Discovery starts when the discovery delay timer expires, which sets event
START_DISCOVERY_EVT. This will result in execution of function timeAppDiscStart. However
if a pairing procedure is in progress when the timer expires discovery will be postponed until
pairing completes. This is done in case the peer device requires security before its characteristics
are read or written.
A service discovery procedure is performed for each service until discovery has been attempted
on all services of interest. The service discovery procedure is generalized as follows:
1. Discovery the service by UUID.
2. If found, discover all characteristics of the service. Cache the handles of characteristics of
interest.
3. If a discovered characteristic uses a client characteristic configuration descriptor
(abbreviated as CCCD in the code), discover all descriptors of the characteristic.
If the mandatory characteristics and descriptors of the service are discovered then discovery of
the service is deemed successful.
The handles of discovered characteristics of interest are stored in array timeAppHdlCache.
The main service discovery function is timeAppDiscGattMsg. This function is executed when a
discovery-related GATT message response is received. This function then executes a separate
discovery function for each service. The service discovery state is maintained in variable
timeAppDiscState.
16.2.5 Service Configuration
When service discovery completes the service configuration procedure is initiated. This procedure
reads and writes characteristics of interest in the discovered services.
The main service configuration function is timeAppConfigNext. This function searches the
cached handle array for the next characteristic of interest, and once found it performs a read or
write on that characteristic.
When a GATT read response or write response is received, function timeAppConfigGattMsg is
called. This function processes the received response and performs an action, such as updating
the clock display, and then calls timeAppConfigNext to initiate the next read or write.
The application writes all discovered client characteristic configuration descriptors to enable
notification or indication. The application also reads some characteristics and then performs no
action with the received response. This is done simply for testing and demonstration.
16.2.6 Handling Indications and Notifications
Handling of received indications and notifications is performed by function timeAppIndGattMsg.
This function is called when a GATT indication or notification message is received. The function
will process the data in the received message and display it on the LCD.
16.2.7 Clock Time
Page 31 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

SWRU297 Version 1.3.2

The application uses the OSAL Clock service to update and maintain the clock time. When new
date and time data is received from the peer device, function timeAppClockSet is called to
update the time in OSAL and display the updated time on the LCD. The LCD is periodically
updated by an OSAL timer that sets event CLOCK_UPDATE_EVT.

17 Serial Bootloader
This sample allows the user load an image over the UART0-Alt1 port.
C:\Texas Instruments\BLE-CC254x-1.3.2\Projects\ble\SBL\iar\cc254x\sbl.eww
17.1 Basic Operation
The SBL is a utility application allowing the user download an image over the serial port. This
might be useful for field updates or allowing an external MCU to change firmware without using
the CC Debugger. The example provided in this release is specific to UART0-Alt1, although
source is provided if modification to settings is required.
17.1.1 Build and Flash the SBL
Build the sbl project and flash it to CC254X.
17.1.2 Build the Project to be Bootloaded
This release contains an example project which creates a bootload compatible image. The
example project is located at
C:\TexasInstruments\BLE-CC254x-1.3.2\Projects\ble\HostTestApp\CC2540\
HostTestRelease.ewp
Select the CC2540-EM-SBL project configuration, and build the project. The .bin is located at
C:\TexasInstruments\BLE-CC254x-1.3.2\Projects\ble\HostTestApp\CC2540\CC2540EMSBL\Exe\HostTestReleaseCC2540-SBL.bin
17.1.3 Download the User Project Image (.bin)
TI provides a PC tool to download the image. The latest version can be found on our wiki at
http://processors.wiki.ti.com/index.php/Category:BluetoothLE .
To re-bootload send the HCI_EXT_UTIL_FORCE_BOOT command, to put a device back in
bootloader mode.

18 USB Bootloader
This sample application allows the user load an image over the USB port.
18.1 Basic Operation
The UBL is a utility application allowing the user to download an image to the USB dongle by
drag and drop in Microsoft Windows. This would be useful for updating the firmware on a USB
dongle when no programming pins are available. The example provided in this release is specific
to USB dongle and Nano dongle.
18.1.1 Flash UBL
The UBL is provided as a hex file. Some source is provided, but this is only for reference. Flash
the image using the TI Flash Programmer.
For USB Dongle provided with CC2540DK-mini kit use
C:\Texas Instruments\BLE-CC254x-1.3.2\Projects\ble\UBL\soc_8051\usb_msd\bin\ ubl_cc2540dk.hex
For the Nano dongle use
C:\Texas Instruments\BLE-CC254x-1.3.2\Projects\ble\UBL\soc_8051\usb_msd\bin\ ubl_cc2540nano.hex
18.1.2 Build the Project to be Bootloaded
Page 32 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

SWRU297 Version 1.3.2

This release contains an example project which creates a bootload compatible image. The
example project is located at
C:\Texas Instruments\BLE-CC254x1.3.2\Projects\ble\HostTestApp\CC2540\HostTestRelease.ewp
Select the CC2540USB-UBL project configuration, and build the project. The .bin is located at
C:\TexasInstruments\BLE-CC254x-1.3.2\Projects\ble\HostTestApp\CC2540\CC2540USBUBL\Exe\ HostTestReleaseCC2540USB-UBL.bin
18.1.3 Download the User Project Image (.bin)
Once the bootloader has been flashed, the USB dongle will show up as a mass storage device.
Use Microsoft Windows explorer to drag and drop the HostTestReleaseCC2540USB-UBL.bin to
the mass storage. Once it is copies over, the dongle will change and register with Windows as a
virtual com port. Press and hold the USB dongle button furthest from port while inserting the
dongle to run the bootloader again. The nano dongle will enter mass storage on insertion, but will
stay in that mode for a short amount of time only.

19 Over Air Download
OAD is an extended stack feature provided as a value-enhancing solution for updating code in
deployed devices without the cost of physical access via a programming header. OAD is a clientserver mechanism in which one device acts as the OAD image server (OAD manager) and the
other device is the OAD image client (OAD target).
19.1 Target Requirements
The target must be setup with a BIM (Boot Image Manager) and at least one image with OAD
profile support.
The BIM project can be found at
C:\Texas Instruments\BLE-CC254x-1.3.2\Projects\ble\util\BIM\cc254x\BIM.eww
An Example of an Image with OAD support is
C:\Texas Instruments\BLE-CC254x1.3.2\Projects\ble\SimpleBlePeripheral\CC254xDB\SimpleBlePeripheral.eww
19.2 Server Requirements
The installer includes a server application compatible with the SBL Tool which runs on the
SmartRF board. The project allows the user to connect load an image over the serial port, and
then transfer it over the air to the target.
This example server application is located at
C:\Texas Instruments\BLE-CC254x1.3.2\Projects\ble\OADManager\CC2541DB\OADManager.eww
In addition, other servers can be used such as a phone with BLE support or a PC. For PC
support, there is dev monitor application which can be found on TI CC2541 product page.
http://www.ti.com/product/cc2541
For iOS, there is a sensorTag application which performs OAD. For more information visit the
SensorTag wiki
http://processors.wiki.ti.com/index.php/SensorTag_User_Guide
19.3 OAD Developer’s Guide
A detailed guide on OAD can be found on the Texas Instruments wiki page.
http://processors.wiki.ti.com/images/8/82/OAD_for_CC254x.pdf
Page 33 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

SWRU297 Version 1.3.2

Page 34 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

SWRU297 Version 1.3.2

20 General Information
20.1 Document History
Table 1: Document History
Revision

Date

Description/Changes

1.0

2011-07-13

Initial release, documenting sample applications included in BLEv1.1 release

1.2

2012-02-07

Updated to align with BLEv1.2 release sample applications.

1.2.2

2012-04-12

Updated with Glucose Collector/Sensor sample applications

1.3.2

2013-06-13

Updated with Sensor Tag, OAD, Advanced Remote

21 Address Information
Texas Instruments Norway AS
Gaustadalléen 21
N-0349 Oslo
NORWAY
Tel: +47 22 95 85 44
Fax: +47 22 95 85 46
Web site: http://www.ti.com/lpw

22 TI Worldwide Technical Support
Internet
TI Semiconductor Product Information Center Home Page:
TI Semiconductor KnowledgeBase Home Page:

support.ti.com
support.ti.com/sc/knowledgebase

TI LPRF forum E2E community http://www.ti.com/lprf-forum

Product Information Centers
Americas
Phone:
Fax:
Internet/Email:

+1(972) 644-5580
+1(972) 927-6377
support.ti.com/sc/pic/americas.htm

Europe, Middle East and Africa
Phone:
Belgium (English)
Finland (English)
France
Germany
Israel (English)
Italy
Netherlands (English)
Russia
Spain
Sweden (English)
United Kingdom
Fax:
Internet:

+32 (0) 27 45 54 32
+358 (0) 9 25173948
+33 (0) 1 30 70 11 64
+49 (0) 8161 80 33 11
180 949 0107
800 79 11 37
+31 (0) 546 87 95 45
+7 (0) 95 363 4824
+34 902 35 40 28
+46 (0) 8587 555 22
+44 (0) 1604 66 33 99
+49 (0) 8161 80 2045
support.ti.com/sc/pic/euro.htm

Page 35 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

SWRU297 Version 1.3.2

Japan
Fax

International

+81-3-3344-5317

Internet/Email

Domestic
International

0120-81-0036
support.ti.com/sc/pic/japan.htm

Domestic

www.tij.co.jp/pic

International

+886-2-23786800

Domestic
Australia
China
Hong Kon
India
Indonesia
Korea
Malaysia
New Zealand
Philippines
Singapore
Taiwan
Thailand

Toll-Free Number
1-800-999-084
800-820-8682
800-96-5941
+91-80-51381665 (Toll)
001-803-8861-1006
080-551-2804
1-800-80-3973
0800-446-934
1-800-765-7404
800-886-1028
0800-006800
001-800-886-0010
+886-2-2378-6808
tiasia@ti.com or ti-china@ti.com
support.ti.com/sc/pic/asia.htm

Asia
Phone

Fax
Email
Internet

Page 36 of 37
Copyright © 2011-2013 Texas Instruments, Inc

TI CC2540 Bluetooth Low Energy Sample Applications Guide v1.3.2

SWRU297 Version 1.3.2

IMPORTANT NOTICE
Texas Instruments Incorporated and its subsidiaries (TI) reserve the right to make corrections, modifications,
enhancements, improvements, and other changes to its products and services at any time and to discontinue any product
or service without notice. Customers should obtain the latest relevant information before placing orders and should verify
that such information is current and complete. All products are sold subject to TI’s terms and conditions of sale supplied at
the time of order acknowledgment.
TI warrants performance of its hardware products to the specifications applicable at the time of sale in accordance with
TI’s standard warranty. Testing and other quality control techniques are used to the extent TI deems necessary to support
this warranty. Except where mandated by government requirements, testing of all parameters of each product is not
necessarily performed.
TI assumes no liability for applications assistance or customer product design. Customers are responsible for their
products and applications using TI components. To minimize the risks associated with customer products and
applications, customers should provide adequate design and operating safeguards.
TI does not warrant or represent that any license, either express or implied, is granted under any TI patent right, copyright,
mask work right, or other TI intellectual property right relating to any combination, machine, or process in which TI
products or services are used. Information published by TI regarding third-party products or services does not constitute a
license from TI to use such products or services or a warranty or endorsement thereof. Use of such information may
require a license from a third party under the patents or other intellectual property of the third party, or a license from TI
under the patents or other intellectual property of TI.
Reproduction of TI information in TI data books or data sheets is permissible only if reproduction is without alteration and
is accompanied by all associated warranties, conditions, limitations, and notices. Reproduction of this information with
alteration is an unfair and deceptive business practice. TI is not responsible or liable for such altered documentation.
Information of third parties may be subject to additional restrictions.
Resale of TI products or services with statements different from or beyond the parameters stated by TI for that product or
service voids all express and any implied warranties for the associated TI product or service and is an unfair and
deceptive business practice. TI is not responsible or liable for any such statements.
TI products are not authorized for use in safety-critical applications (such as life support) where a failure of the TI product
would reasonably be expected to cause severe personal injury or death, unless officers of the parties have executed an
agreement specifically governing such use. Buyers represent that they have all necessary expertise in the safety and
regulatory ramifications of their applications, and acknowledge and agree that they are solely responsible for all legal,
regulatory and safety-related requirements concerning their products and any use of TI products in such safety-critical
applications, notwithstanding any applications-related information or support that may be provided by TI. Further, Buyers
must fully indemnify TI and its representatives against any damages arising out of the use of TI products in such safetycritical applications.
TI products are neither designed nor intended for use in military/aerospace applications or environments unless the TI
products are specifically designated by TI as military-grade or "enhanced plastic." Only products designated by TI as
military-grade meet military specifications. Buyers acknowledge and agree that any such use of TI products which TI has
not designated as military-grade is solely at the Buyer's risk, and that they are solely responsible for compliance with all
legal and regulatory requirements in connection with such use.
TI products are neither designed nor intended for use in automotive applications or environments unless the specific TI
products are designated by TI as compliant with ISO/TS 16949 requirements. Buyers acknowledge and agree that, if they
use any non-designated products in automotive applications, TI will not be responsible for any failure to meet such
requirements.
Following are URLs where you can obtain information on other Texas Instruments products and application solutions:
Products

Applications

Amplifiers
Data Converters

amplifier.ti.com
dataconverter.ti.com

Audio
Automotive

www.ti.com/audio
www.ti.com/automotive

DSP

dsp.ti.com

Broadband

www.ti.com/broadband

Interface

interface.ti.com

Digital Control

www.ti.com/digitalcontrol

Logic

logic.ti.com

Military

www.ti.com/military

Power Mgmt

power.ti.com

Optical Networking

www.ti.com/opticalnetwork

Microcontrollers

microcontroller.ti.com

Security

www.ti.com/security

Telephony

www.ti.com/telephony

Video & Imaging

www.ti.com/video

Wireless

www.ti.com/wireless

Mailing Address: Texas Instruments, Post Office Box 655303, Dallas, Texas 75265
Copyright 2011-2012, Texas Instruments Incorporated

Page 37 of 37
Copyright © 2011-2013 Texas Instruments, Inc



Source Exif Data:
File Type                       : PDF
File Type Extension             : pdf
MIME Type                       : application/pdf
PDF Version                     : 1.5
Linearized                      : No
Page Count                      : 37
Language                        : en-US
Tagged PDF                      : Yes
Producer                        : Microsoft® Word 2010
Creator                         : Microsoft® Word 2010
Create Date                     : 2013:06:13 17:13:03-07:00
Modify Date                     : 2013:06:13 17:13:03-07:00
EXIF Metadata provided by EXIF.tools

Navigation menu