1 Version History ________________________________________________________________________ 4
2 Introduction to Bluegiga Bluetooth Low Energy Software ________ ________________________________ 7
2.1The Bluegiga Bluetooth Low Energy Stack ______________________________________________ 7
2.2The Bluegiga Bluetooth Low Energy SDK _______________________________________________ 8
1.3API documentation for SW version v.1.0.3 (Build 43)
2.0API documentation for v.1.1.0 beta (Build 46)
2.1API documentation for v.1.1.0 beta (Build 55)
Note: API changes history is now included here (not separate)
Changed APIs:
* Attribute Database – User Read Response (function implemented for Beta 2)
* Connection – Connection Status Flags (fixed)
Doc improved for following APIs:
* Attribute Client – Attribute Value, Indicated, Procedure Completed, Group Found
* Attribute Database – User Read Request
* Generic Access Profile – Discover, Set Adv Parameters
* Hardware – I2c Read, I2c Write, Set Soft Timer, Set Txpower
* Security Manager – Delete Bonding, Get Bonds
* System – Whitelist Append
Other sections (outside API reference) has also been updated to improve the document
2.2Added documentation how to use BGAPI protocol without UART flow control.
Section updated: BGAPI protocol definition
2.3API documentation for v1.1.0 (Build 71+)
* Various typos and wording corrected.
3.0Documentation updates for SW v1.2 compatibility
Changed APIs:
Channel quality testing commands added: Get Channel Map and Channel mode
Out of Bonds and Command Too Long error code added
Protocol error event added for indicating the invalid command or wrong length
GAP Discoverable Mode is updated to support the Enhanced Broadcasting.
Doc improved for following APIs/referenses:
Updated ADC internal reference to 1.24V (was 1.15V),
GAP - Set Scan Paremeters, Connect Selective, Connect Direct
3.1Documentation updates for SW v1.2.2 compatibility
Added APIs:
Added API's for reading (Read Data), writing (Write Data), and erasing (Erase Page) the
user area data on the internal flash memory
Added API's for handling I/O port interrupts (Io Port Irq Enable) and setting the directions (Io
Port Irq Direction)
Added testing API's for sending and receiving data (Phy Tx, Phy Rx, Phy End)
Added API's for handling the comparator functionality under HW commands and events.
Silicon LabsPage of 4220
Version
3.2Documentation updates for SW v1.3.0 compatibility
Added APIs:
Added Set RXGain API for controlling RX Gain for lowering the sensitivity (Hardware
commands)
Added Usb Enable API for controlling whether USB interface is on or off (Hardware
commands)
Added AES API’s for using AES engine for de-/encryptions (System commands)
3.3Documentation updates for SW v1.3.1 compatibility
Added APIs:
Added Send Attributes (attributes_send) command for controlling sending of notifications
and indications (Attributes commands)
Added Whitelist Bonds (sm_whitelist_bonds) command for adding all the bonded
devices to the whitelist (Security Manager commands).
3.4Editorial changes and improvements and enhancements to command, response and event
descriptions.
3.5Editorial changes and improvements and enhancements to command, response and event
descriptions.
3.6Updates for the software v.1.4.0
New API added : Set Initiating Con Parameters
New API added : Slave Latency Disable
iOS9.1 pairing pairing instructions: Encrypt Start
3.7New API added: Set Pairing Distribution Keys
3.8New API added: Sleep Enable
3.9New API added: Set Nonresolvable Address
Updated API: Set Privacy Flags
3.10Updates for the software v.1.5.0
Corrected AFH Description in section.Connections and packet timings
New API added: and commands description.Channel Map SetChannel Map Get
Corrected and descriptions.Attribute WriteWrite Command
Added note about packet mode responses in BGAPI protocol definition
Refined descriptionPhy Tx
3.11Updates for the software v.1.6.0
Corrected type, added Bluetooth 4.0 specification reference in
lolen
Set Initiating Con
section.Parameters
Added Bluetooth 4.0 specification reference in section.Set Scan Parameters--gap
Silicon LabsPage of 5220
Version
3.12Removed "Introduction to Bluetooth Smart Technology" paragraph
Updates for the software v.1.7.0
New BGAPI error code for BGScript stack overflow
I2C commands timeout documentation
New API added: Get Bootloader Crc
New API added: Delay Reset
New API added: Get Timestamp
New API added: USB Enumeration Status Get
New API event added: USB Enumerated
4.0Updates for the software v.1.8.0
New API event added: Radio Error
4.1Renamed "Bluetooth Smart" to "Bluetooth Low Energy" according to the official Bluetooth SIG
nomenclature.
Silicon LabsPage of 6220
2
The Bluegiga Low Energy Software enables developers to quickly and easily develop Low
BluetoothBluetooth
Energy applications without in-depth knowledge of the Low Energy technology. The Low
BluetoothBluetooth
Energy Software consists of two main parts:
The Low Energy Stack
Bluetooth
The Low Energy Software Development Kit (SDK)
Bluetooth
2.1
The Low Energy is meant for the Bluegiga Low Energy products such as BLE112, BLE113
BluetoothBluetooth
BLE121LR and BLED112.
Figure: The Bluegiga Bluetooth Low Energy Stack
Introduction to Bluegiga Bluetooth Low Energy Software
The Bluegiga Bluetooth Low Energy Stack
The
BluetoothBluetooth
slave and master modes, all the protocol layers such as L2CAP, Attribute Protocol (ATT), Generic Attribute
Profile (GATT), Generic Access Profile (GAP) and Security Manager (SM). The Bluetooth Low Energy stack
also implements various other features such as interface APIs to SPI, UART, GPIO, ADC, flash etc. and other
features like the Device Firmware Update (DFU) API.
Low Energy stack is a fully
4.0 single mode compatible software stack implementing
Silicon LabsPage of 7220
2.2 The Bluegiga Bluetooth Low Energy SDK
The Bluegiga Low Energy SDK is a software development kit, which enables the device and software
Bluetooth
vendors to develop products on top of the Bluegiga’s Low Energy hardware and software.
Bluetooth
The Low Energy SDK supports multiple development models and the software developers can decide
Bluetooth
whether the device’s application software runs on a separate host (for example a MCU) or whether they want to
make fully standalone devices and execute their application on-board the Bluegiga Low Energy
Bluetooth
modules.
The SDK also contains documentation, tools for compiling the firmware, installing it into the hardware and lot of
example application speeding up the development process.
The SDK contains the following components:
Bluetooth Low Energy
The BGAPIprotocol
TM
is a binary based commend and response protocol that allows the Bluetooth
Low Energy stack to be controller form an external host and an application over for example UART or
USB interface.
The BGScript scripting language TMis a simple BASIC like scripting language that allows the software
developers to embed applications on-board the Bluegiga Low Energy modules. The BGScript
Bluetooth
applications are executed in the BGScript Virtual Machine (VM) and the benefit of this is that no external
host MCU is required.
The BGLIBhost library
TM
is a lightweight parser for the BGAPI host protocol and it implements C
functions and callback handlers for all the BGAPI commands, responses and events. The benefit of the
BGLIB library is that speeds up the application development for the external host processors.
The Profile ToolkitTM is a simple XML based description language that enables quick and easy
development of GATT Bluetooth Low Energy services and characteristics on a device.
Each of these components are described in more detail in the following chapters.
Silicon LabsPage of 8220
2.3
needed between the host and the Low Energy stack. The transport protocol is used to communicate
Bluetooth
with the stack as well to transmit and receive data packets. This protocol is called BGAPI and it's a
Bluetooth
lightweight binary based communication protocol designed specifically for ease of implementation within host
devices with limited resources.
The BGAPI protocol is a simple command, response and event based protocol and it can be used over UART
or USB physical interfaces.
Figure: BGAPI message exchange
The BGAPI provides access for example to the following layers in the Low Energy Stack:
Bluetooth
The BGAPI TM Protocol
For applications where a separate host is used to implement the end user application, a transport protocol is
Generic
open connections
Security
Attribute Database - An class to access the local Attribute Database
Attribute
Connection - Provides an interface to manage
Hardware - An interface to access the various hardware layers such as timers, ADC and other hardware
interfaces
Persistent Store - User to access the parameters of the radio hardware and read/write data to non-
volatile memory
System
Access Profile
Manager -
Client - Provides
- Various system functions, such as querying the hardware status or reset it
- GAP allows the management of discoverability and connetability modes and
Provides access the
an interface
Bluetooth
discover, read
to
low energy security functions
write remote attributes
and
Bluetooth
low energy connections
Silicon LabsPage of 9220
2.4
Figure: The BGLIB host library
The BGLIB TM Host Library
For easy implementation of BGAPI protocol an ANSI C host library is available. The library is easily portable
ANSI C code delivered within the Low Energy SDK. The purpose is to simplify the application
development to various host environments.
Bluetooth
Silicon LabsPage of 10220
2.5
The BGScript TM Scripting Language
without a separate host MCU and run all the application code on the Bluegiga Low Energy modules.
Bluetooth
The Low Energy modules can run simple applications along the Low Energy stack and this
BluetoothBluetooth
provides a benefit when one needs to minimize the end product’s size, cost and current consumption. For
developing standalone Low Energy applications the SDK includes a BGScript VM, compiler and other
Bluetooth
BGScript development tools. BGScript provides access to the same software and hardware interfaces as the
BGAPI protocol and the BGScript code can be developed and compiled with free-of-charge tools provided by
Bluegiga.
Typical BGScript applications are only few tens to hundreds lines of code, so they are really quick and easy to
develop and lots of readymade examples are provides with the SDK.
Figure: BGScript application model
Figure: BGScript code example
The
Bluetooth
Low Energy SDK Also allows the application developers to create fully standalone devices
Silicon LabsPage of 11220
2.6
The Profile Toolkit TM
Figure: A profile toolkit example of GAP service
The
Bluetooth
Bluetooth
description language and templates, which can be used to describe the devices GATT database. The profile
toolkit also contains a compiler, which converts the XML to binary format and generates API to access the
characteristic values.
Low Energy profile toolkit is a simple set of tools, which can used to describe GATT based
Low Energy services and characteristics. The profile toolkit consists of a simple XML based
Silicon LabsPage of 12220
3 API definition
The BGAPIhost protocol API definition
TM
The BGLIB host library API description
TM
TM
OctetOctet bitsLengthDescriptionNotes
Octet 071 bit
Message Type (MT)0: Command/Response
Event1:
...6:34 bits
Technology Type (TT)0000:
...2:03 bits
Length High (LH)
Payload length (high bits)
Octet 17:08 bits
Length Low (LL)
Payload length (low bits)
Octet 27:08 bits
Class ID (CID)
Command class ID
Octet 37:08 bits
Command ID (CMD)
Command ID
Octet 4-n-0 - 2048 Bytes
Payload (PL)
Up to 2048 bytes of payload
With the Bluegiga
Bluetooth
3.1.1 Message types
The following message types exist in the BGAPI protocol.
Table: BGAPI message types
This section of the document contains the generic Bluetooth Low Energy Stack API
definition. The definition consist of three parts:
The BGScript scripting language API description
This section of the document only provides the generic definition and description of the API. The actual
commands, responses and events are described in detail in the section.API reference
3.1 The BGAPI protocol definition
The BGAPI protocol is a command, response and event protocol that can be used to communicate with the
Bluetooth
used to instruct the
BluetoothBluetooth
The BGAPI commands, responses and events use a binary format and the generic protocol format is described
in this section.
BGAPI Packet format
Low Energy stack over one of the physical interfaces like UART or USB. The BGAPI protocol can be
Bluetooth
devices or access the physical interfaces like SPI or I2C of the
Low Energy stack to do something like advertise, discover and connect other
Low Energy module.
The generic BGAPI protocol format is described in the table below. The BGAPI protocol uses a four (4) byte
header and data payload.
Packets in either direction use the following format.
Table: BGAPI packet format
bytes and
header so the maximum payload size is 60 bytes.
longer packet sizes cannot be used. Four (4) bytes will be used for the BGAPI protocol
Low Energy
products the maximum allowed BGAPI packet size is 64
Low EnergyBluetooth
: Wi-Fi0001
Silicon LabsPage of 13220
Message typeMessage Type (MT)
Value
Description
Command0x00Command from host to the stack
Response0x00Response from stack to the host
Event0x80Event from stack to the host
Silicon LabsPage of 14220
3.1.2 Command Class IDs
The following command classes exist.
Table: BGAPI command classes
Class IDDescriptionExplanation
0x00SystemProvides access to system functions
0x01Persistent StoreProvides access the persistence store (parameters)
0x02
Provides access to local GATT database
0x03ConnectionProvides access to connection management functions
0x04
Functions to access remote devices GATT database
0x05Security ManagerBluetooth low energy security functions
0x06Generic Access ProfileGAP functions
0x07HardwareProvides access to hardware such as timers and ADC
3.1.3 Packet Exchange
The BGAPI protocol is a simple command / response protocol and the BGAPI messages are exchanged as
show in the picture below.
The command messages are transmitted from the Application to the Stack and the Stack provides a response
to every successfully received command.
Some commands may generate events, which are transmitted from the Stack to the Application.
Attribute Database
Attribute Client
Silicon LabsPage of 15220
The Application should always wait for the response to a command before issuing another command.
Silicon LabsPage of 16220
Using BGAPI protocol without UART flow control (Packet mode)
By default the BGAPI protocol assumes that UART flow control (RTS/CTS) is used to ensure reliable data
transmission and to prevent lost data because of buffer overflows. It is however possible to use the BGAPI
protocol without UART flow control.
When using the BGAPI protocol without UART flow control over a simple 2-wire (TX and RX) UART interface
and additional needs to be added to the BGAPI packets, which tells the total length of the BGAPI
length byte
packet excluding the itself. This is used by the BGAPI protocol parser to identify the length of
length byte
incoming commands and data and make sure they are fully received.
In this case the BGAPI protocol uses the following format:
Table: BGAPI packet format
OctetOctet
bits
LengthDescriptionNotes
Octet 07:08 bits
BGAPI command
length
Tells the length of the BGAPI command excluding the
length byte itself
Range of this octet is 4 - 62
Octet 171 bit
Message Type
(MT)
0: Command/Response
Event1:
...6:34 bits
Technology Type
(TT)
0000: Bluetooth Low Energy
Wi-Fi0001:
...2:03 bits
Length High (LH)
Payload length (high bits)
Octet 27:08 bits
Length Low (LL)
Payload length (low bits)
Octet 37:08 bits
Class ID (CID)
Command class ID
Octet 47:08 bits
Command ID
(CMD)
Command ID
Octet
5-n
-0 - 2048
Bytes
Payload (PL)
Up to 64 bytes of payload
This operational mode needs to be especially enabled in devices hardware configuration file (typically
) and is not used by default. The default operational mode assumes a UART with flow hardware.xml
control is used.
Below is a simple example which shows how a command (Raw: 0x00 0x00 0x00 0x08) is sent System Get Info
using the BGAPI packet format.
Silicon LabsPage of 17220
Packet mode responses
The extra length byte required in Packet Mode is only used in the traffic from host to the stack. When
the Bluetooth stack produces responses or events to the host the length byte is not included in them.
Silicon LabsPage of 18220
3.2 The BGLIB functions definition
Bluegiga provides a reference parser for the BGAPI protocol called the BGLIB. The BGLIB is an ANSI C
implementation of BGAPI packet parser and it's provided in source code format with the Bluegiga Bluetooth Low
Energy SDK. The purpose of the BGLIB is to simplify and speed up the development process and also to
provide higher level, easier to use C functions and callbacks so the developers do not need to fully learn the
raw BGAPI protocol.
In BGLIB all of the BGAPI commands are available as C functions and for the BGAPI responses and events
there are callback handlers.
The BGLIB functions and callbacks are documented as show below:
The command parameters and return values are the same as used in the BGAPI protocol and they are not
documented separately in the API reference section.
Callback programming
Callback programming is a style of computer programming, which allows lower layer of software to call functions
defined on a higher layer. Callback is piece of code or a reference to a piece of code that is passed as an
argument. The figure below illustrates the callback architecture used with BGLIB.
Figure: Callback
are not familiar with callback programming a basic tutorial can for example be found
The BGScript functions are also documented in the API reference section. The format of the commands varies
slightly from the BGLIB functions and instead of using callbacks the BGScript functions take the return values
as parameters.
The BGScript command parameters and return values are the same as used in the BGAPI binary protocol and
they are not documented separately.
Silicon LabsPage of 20220
3.4
Data Types
TypeDescriptionExample: Human
readable
Example Packet data in
hex
int8
signed integer stored in 1 byte twos
complement form
-420xd6
uint8
unsigned integer stored in 1 byte420x2a
uint16
unsigned integer stored in 2 bytes little
endian format
17010xa5 0x06
uint32
unsigned integer stored in 4 bytes little
endian format
10000000x40 0x42 0x0f 0x00
uint8array
byte array, first byte is array size"Hello"0x05 0x68 0x65 0x6c
0x6c 0x6f
bd_addr
Bluetooth address in little endian format00:07:80:c0:ff:ee0xee 0xff 0xc0 0x80 0x07
0x00
The following data types are used in this documentation.
Table: Used data types
Silicon LabsPage of 21220
4 API Reference
This section of the document contains the actual API description, so the description of commands, responses,
events and enumerations and their possible parameters and values. The high level categorization is made
based on the command classes, which are:
DescriptionExplanation
Provides access to local GATT database and allows data to be written there for remote
devices to access it.
Provides access to ATT protocol operationsa and allows a remote devices data to be
accessed.
ConnectionProvides access to connection and status management
Bluetooth
Generic Access
Profile
Provides access to GAP functions which allows one to control the local
Bluetooth
devices discoverability and connectability
HardwareProvides access to hardware interfaces such as SPI, I2C, timers and ADC
Persistent StoreProvides access to the local persistence store, which allows data to be written and read
to the devices flash.
Security Manager
Provides
to security functions
Bluetooth
SystemProvides access to various system functions
TestingFunctions needed for conformance testing
Bluetooth
Device Firmware
Upgrade
Provides access to functions required for field firmware upgrades
Final section of the API reference contains description of the error codes categorized as follows:
Description
BGAPI errors
Bluetooth errors
Attribute protocols errors
Attribute Database
Attribute Client
Security Manager errors
Silicon LabsPage of 22220
4.1
Attribute Client
This command should be used for writing data to characteristic with property write="true".
The data payload for the Attribute Write command can be up to 20 bytes.
The Attribute Client class implements the
to the ATT protocol methods. The Attribute Client class can be used to discover services and characteristics
from the ATT server, read and write values and manage indications and notifications.
Bluetooth
Low Energy Attribute Protocol (ATT) and provides access
4.1.1 Commands
Attribute Client commands
Attribute Write
This command can be used to write an attributes value on a remote device. In order to write the value of an
attribute a
A successful attribute write will be acknowledged by the remote device and this will generate an event
the Bluetooth connection will be dropped.
Bluetooth
connection must exists and you need to know the handle of the attribute you want to write.
. The acknowledgement should happen within a 30 second window or otherwise attclient_procedure_completed
Silicon LabsPage of 23220
EventDescription
attclient
procedure_completed
This event is generated when the write operation has been acknowledged by
remote device.
This command can be used to find specific attributes on a remote device based on their 16-bit UUID value and
value. The search can be limited by a starting and ending handle values.
The command returns the handles of all attributes matching the type (UUID) and value.
Table: COMMAND
Silicon LabsPage of 27220
);
/* Callback */
struct ble_msg_attclient_find_by_type_value_rsp_t{
uint8 connection,
uint16 result
}
This command can be used to send a acknowledge a received indication from a remote device. This function
allows the application to manually confirm the indicated values instead of the
automatically doing it. The benefit of this is extra reliability since the application can for example store the
received value on the flash memory before confirming the indication to the remote device.
Bluetooth
Low Energy
stack
Silicon LabsPage of 31220
1.
2.
3.
4.
5.
6.
7.
8.
9.
Prepare Write
attclient_prepare_write(...., partial data)
wait for rsp_attclient_prepare_write
wait for evt_attclient_procedure_completed
attclient_prepare_write(...., partial data)
wait for rsp_attclient_prepare_write
wait for evt_attclient_procedure_completed
attclient_execute_write(1)
wait for rsp_attclient_execute_write
wait for evt_attclient_procedure_completed
It is not mandatory for an ATT server to support this command. It is only recommended to use this
command to write long-attributes which do not fit in single ATT packet.
This command will send a prepare write request to a remote device for queued writes. Queued writes can for
example be used to write large attribute values by transmitting the data in chunks using prepare write
command.
Once the data has been transmitted with multiple prepare write commands the write must then be executed or
canceled with
event.Completed
The example below shows how this approach can be used to write a 30-byte characteristic value:
command, which if acknowledged by the remote device triggers a Execute WriteProcedure
Silicon LabsPage of 32220
Table: EVENTS
EventDescription
attclient procedure_completedWrite operation has been acknowledged by remote end
This command reads the value of each attribute of a given type and in a given handle range.
The command is typically used for primary (UUID: 0x2800) and secondary (UUID: 0x2801) service discovery.
Discovered services are reported by
event.Group Found
Finally when the procedure is completed a
Table: COMMAND
event is generated.Procedure Completed
Silicon LabsPage of 34220
struct ble_msg_attclient_read_by_group_type_rsp_t{
uint8 connection,
uint16 result
}
The command reads the value of each attribute of a given type (UUID) and in a given attribute handle range.
The command can for example be used to discover the characteristic declarations (UUID: 0x2803) within a
service.
Table: COMMAND
Silicon LabsPage of 38220
struct ble_msg_attclient_read_by_type_rsp_t{
uint8 connection,
uint16 result
}
This command can be used to read long attribute values, which are longer than 22 bytes and cannot be read
with a simple
The command starts a procedure, where the client first sends a normal read command to the server and if the
returned attribute value length is equal to MTU, the client will send further read long read requests until rest of
the attribute is read.
Write command will not be acknowledged by the remote device unlike . This command Attribute Write
should be used for writing data to characteristic with property write_no_response="true".
The maximum data payload for Write Command is 20 bytes.
0attclient_attribute_value_type_readValue was read
1attclient_attribute_value_type_notifyValue was notified
2attclient_attribute_value_type_indicateValue was indicated
3attclient_attribute_value_type_read_by_typeValue was read
4attclient_attribute_value_type_read_blobValue was part of a long attribute
5attclient_attribute_value_type_indicate_rsp_reqValue was indicated and the remote device is
waiting for a confirmation.
Indicate Confirm command can be used to send a
confirmation.
Attribute Client enumerations
Attribute Value Types
These enumerations are in the Attribute Client class
This event is produced at the GATT client side when an attribute value is passed from the GATT server to the
GATT client. This event is for example produced after a successful
attribute is indicated or notified by the remote device.
This event is produced at the GATT server side when an attribute is successfully indicated to the GATT client.
This means the event is only produced at the GATT server if the indication is acknowledged by the GATT client
(the remote device).
Table: EVENT
Silicon LabsPage of 50220
Procedure Completed
This event is for example produced after an command is successfully used to write a value to a Attribute Write
remote device.
The Attribute Database class provides methods to read and write attributes to the local devices Attribute
Database. This class is usually only needed on sensor devices (Attribute server) for example to update
attribute values to the local database based on the sensor readings. A remote device then can access the
GATT database and these values over a
4.2.1 Commands
Attribute Database commands
Read
The command reads the given attribute's value from the local database. There is a 32-byte limit in the amount
of data that can be read at a time. In order to read larger values multiple read commands must be used with the
offset properly used.
This command will send an attribute value, identified by handle, via a notification or an indication to a remote
device, but does not modify the current corresponding value in the local GATT database.
If this attribute, identified by handle, does not have notification or indication property, or no remote device has
registered for notifications or indications of this attribute, then an error will be returned.
This command is used to respond to an attribute Read request by a remote device, but only for attributes which
have been configured with the user property. Attributes which have the user property enabled allow the attribute
value to be requested from the application instead of the
with
the data in it's local GATT database.
Bluetooth
Low Energy
stack automatically responding
This command is normally used in response to a
device tries to read an attribute with a user property enabled.
event, which is generated when a remote User Read Request
The command should be used when a event is received where the reason why value has changed Value
corresponds to .attributes_attribute_change_reason_write_request_user
This response must be sent within 30 seconds or otherwise a timeout will occur.
This command is used by the GATT server to acknowledge to the remote device that the attribute's value was
written. This feature again allows the user application to acknowledged the attribute write operations instead of
the
This event indicates attribute status flags have changed. For example, this even is generated at the module
acting as the GATT Server whenever the remote GATT Client changes the Client Characteristic Configuration
to start or stop notification or indications from the Server.
Table: EVENT
Silicon LabsPage of 63220
User Read Request
This event should be responded within 30 seconds with command either containing the User Read Response
data or an error code.
This command returns the Receiver Signal Strength Indication (RSSI) related to the connection referred to by
the connection handle parameter. If the connection is not open, then the RSSI value returned in the response
packet will be 0x00, while if the connection is active, then it will be some negative value (2's complement form
between 0x80 and 0xFF and never 0x00). Note that this command also returns an RSSI of 0x7F if you request
RSSI on an invalid/unsupported handle.
This command temporarily enables or disables slave latency.
Table: COMMAND
Update
This command updates the connection parameters of a given connection. The parameters have the same
meaning and follow the same rules as for the GAP class command: .Connect Direct
If this command is issued at a master device, it will send parameter update request to the
On the other hand if this command is issued at a slave device, it will send L2CAP connection parameter update
request to the master, which may either accept or reject it.
Silicon LabsPage of 72220
Bluetooth
link layer.
It will take an amount of time corresponding to at least six times the current connection interval before the new
connection parameters will become active.
This command requests a version exchange of a given connection.
Table: COMMAND
Silicon LabsPage of 75220
4.3.2
Enumerations
ValueNameDescription
bit 0connection_connectedThis status flag tells the connection exists to a remote device.
bit 1connection_encryptedThis flag tells the connection is encrypted.
bit 2connection_completedConnection completed flag, which is used to tell a new connection
has been created.
bit 3connection_parameters_changeThis flag tells that connection parameters have changed and. It is
set when connection parameters have changed due to a link layer
operation.
Connection class enumerations
Connection Status Flags
The possible connection status flags are described in the table below. The flags field is a bit mask, so multiple
flags can be set at a time. If the bit is 1 the flag is active and if the bit is 0 the flag is inactive.
Table: VALUES
Silicon LabsPage of 76220
4.3.3
Events
This event is produced when a connection is disconnected.
The module will enter a state where it continuously scans for the connectable advertisement packets
Bluetooth
from the remote device which matches the Bluetooth address gives as a parameter. Upon receiving the
advertisement packet, the module will send a connection request packet to the target device to imitate a
connection. A successful connection will bi indicated by a event.
Bluetooth
Status
If the device is configured to support more than one connection, the smallest connection interval which is
divisible by will be selected. Thus, it is important to provide minimum and maximum_connections * 2.5ms
maximum connection intervals so that such a connection interval is available within the range.
The connection establishment procedure can be cancelled with command.End Procedure
The lowest possible Connection Interval is 7.50ms and the largest is
4000ms.
13 Â14
uint16conn_interval_max
Maximum Connection Interval (in units of 1.25ms).
Range: 6 - 3200
Must be equal or bigger than minimum Connection Interval.
15 Â16
uint16
timeout
Supervision Timeout (in units of 10ms). The Supervision Timeout
defines how long the devices can be out of range before the
connection is closed.
Range: 10 - 3200
Minimum time for the Supervision Timeout is 100ms and maximum
value is 32000ms.
The Generic Access Profile (GAP) class provides methods to control the
the local device. The GAP call for example allows remote device discovery, connection establishment and local
devices connection and discovery modes. The GAP class also allows the control of local devices privacy
modes.
Bluetooth
GAP level functionality of
4.4.1 Commands
Generic Access Profile class commands
Connect Direct
This command will start the GAP direct connection establishment procedure to a dedicated
Energy device.
Low
Silicon LabsPage of 81220
ByteTypeNameDescription
According to the specification, the Supervision Timeout in
milliseconds shall be larger than (1 + latency) * conn_interval_max
, where conn_interval_max is given in milliseconds.* 2
17 Â18
uint16latency
This parameter configures the slave latency. Slave latency defines
how many connection intervals a slave device can skip.
Increasing slave latency will decrease the energy consumption of
the slave in scenarios where slave does not have data to send at
every connection interval.
Range: 0 - 500
0 : Slave latency is disabled.
Example:
Connection interval is 10ms and slave latency is 9: this means that
the slave is allowed to communicate every 100ms, but it can
communicate every 10ms if needed.
device, and a successful connection will produce a event.connection status
The connect selective command can be cancelled with command.End Procedure
When in there are no events
The lowest possible connection interval is 7.50ms and the largest is
4000ms.
When more then one connection is supported the connection interval
values (minimum and maximum) used in connection commands all
must be divisible by *
connection count 2.5ms
6 - 7
uint16 conn_interval_max
Maximum connection interval (in units of 1.25ms).
Range: 6 - 3200
Must be equal or bigger than minimum connection interval.
8 - 9
uint16 timeout
Supervision timeout (in units of 10ms). The supervision timeout defines
how long the devices can be out of range before the connection is
closed.
Range: 10 - 3200
Minimum time for the supervision timeout is 100ms and maximum
value: 32000ms. Supervision timeout must also be equal or grater than
maximum connection interval.
10 Â11
uint16
latency
This parameter configures the slave latency. Slave latency defines
how many connection intervals a slave device can skip.
Increasing slave latency will decrease the energy consumption of the
slave in scenarios where slave does not have data to send at every
connection interval.
Range: 0 - 500
0 : Slave latency is disabled.
Example:
Connection interval is 10ms and slave latency is 9: this means that the
slave is allowed to communicate every 100ms, but it can communicate
This command will start the GAP direct connection establishment procedure to a set of dedicated Bluetooth
Low Energy devices.
When this command is issued the the
advertisement packets from the remote devices which are registered in the local white list. Upon receiving an
advertisement packet from one of the registered devices, the module will send a connection request to this
Bluetooth
module will enter a state where it scans connectable
uint16result0: Scan procedure was successfully started
: An error occurredNon-zero
Table: EVENTS
EventDescription
gap scan_responseDiscovered device scan response
C Functions
/* Function */
void ble_cmd_gap_discover(
uint8 mode
);
/* Callback */
struct ble_msg_gap_discover_rsp_t{
uint16 result
}
void ble_rsp_gap_discover(
const struct ble_msg_gap_discover_rsp_t * msg
)
BGScript Functions
call gap_discover(mode)(result)
This command starts the GAP discovery procedure to scan for advertising devices i.e. to perform a device discovery.
Scanning parameters can be configured with the Set Scan Parameters
To cancel on an ongoing discovery process use the End Procedure
This commands set advertisement or scan response data used in the advertisement and scan response
packets. The command allows application specific data to be broadcasts either in advertisement or scan
response packets.
The data set with this command is only used when the
Notice that advertisement or scan response data must be formatted in accordance to the Bluetooth Core
Specification. See BLUETOOTH SPECIFICATION Version 4.0 [Vol 3 - Part C - Chapter 11].
Table: COMMAND
mode is set to gap_user_data.GAP discoverable
Silicon LabsPage of 88220
Set Adv Parameters
If you are currently advertising, then any changes set using this command will not take effect until you
stop and re-start advertising.
This command is used to set the advertising parameters.
Example: If the minimum advertisement interval is 40ms and the maximum advertisement interval is 100ms
then the real advertisement interval will be mostly the middle value (70ms) plus a randomly added 20ms delay,
which needs to be added according to the Bluetooth specification.
This command sets device to Directed Connectable mode.
In this mode the device uses fast advertisement procedure for the first 1.28 seconds, after which the device
enters a non-connectable mode. If the device implements the Peripheral Preferred Connection Parameters
This command can be used to set scan, connection, and advertising filtering parameters based on the local
devices white list. See also
Table: COMMAND
command.Whitelist Append
Silicon LabsPage of 92220
Set Initiating Con Parameters
This command sets the scan parameters for Initiating State which affect for establishing BLE connection. See
BLUETOOTH SPECIFICATION Version 4.0 [Vol 6 - Part B - Chapter 4.4.4].
Scan interval defines the interval when scanning is re-started in units of
625us
Range: 0x4 - 0x4000
Default: (31,25ms)0x32
After every scan interval the scanner will change the frequency it operates at
at it will cycle through all the three advertisements channels in a round robin
fashion. According to the specification all three channels must be
Bluetooth
used by a scanner.
6 - 7
uint16 scan_window
Scan Window defines how long time the scanner will listen on a certain
frequency and try to pick up advertisement packets. Scan window is defined
as units of 625us
Range: 0x4 - 0x4000
Default: 0x32 (31,25ms)
Scan windows must be equal or smaller than scan interval
If scan window is equal to the scan interval value, then the module
Bluetooth
will be scanning at a 100% duty cycle.
If scan window is half of the scan interval value, then the module
uint16result0: the command was executed successfully
: An error occurredNon-zero
Table: EVENTS
EventDescription
connection statusSent if device was connectable and master connected to device
C Functions
/* Function */
void ble_cmd_gap_set_mode(
uint8 discover,
uint8 connect
);
/* Callback */
struct ble_msg_gap_set_mode_rsp_t{
uint16 result
}
void ble_rsp_gap_set_mode(
Set Mode
This command configures the current GAP discoverability and connectability modes. It can be used to enable
advertisements and/or allow connection. The command is also meant to fully stop advertising, when using
gap_non_discoverable and gap_non_connectable.
This command set the local device's random Non-Resolvable Bluetooth address. Default local device's random
Non-Resolvable Bluetooth address is 00:00:00:00:00:01.
Table: COMMAND
Silicon LabsPage of 96220
Set Privacy Flags
demand. If peripherial_privacy is set to 2 additionally is called with the current Discoverable and Set Mode
Connectable parameters. Setting up new mode by command does not change generated address.Set Mode
By setting privacy mode to 3, the stack will use a non-resolvable random private address (set by
Bluetooth
Set
command). For example if peripheral_privacy is set to 3, the stack will get a Nonresolvable Address
Bluetooth
non-resolvable random private address for the advertising packets every time the command is used Set Mode
to enter advertising mode.
It is not recommended to adjust peripheral privacy unless mandatory by the application, because not
all implementations can decode resolvable private addresses.
Scan interval defines the interval when scanning is re-started in units of
625us
Range: 0x4 - 0x4000
Default: (46,875ms)0x4B
After every scan interval the scanner will change the frequency it operates at
at it will cycle through all the three advertisements channels in a round robin
fashion. According to the specification all three channels must be
Bluetooth
used by a scanner.
6 - 7
uint16 scan_window
Scan Window defines how long time the scanner will listen on a certain
frequency and try to pick up advertisement packets. Scan window is defined
as units of 625us
Range: 0x4 - 0x4000
Default: 0x32 (31,25 ms)
Scan windows must be equal or smaller than scan interval
If scan window is equal to the scan interval value, then the module
Bluetooth
will be scanning at a 100% duty cycle.
If scan window is half of the scan interval value, then the module
Bluetooth
will be scanning at a 50% duty cycle.
8
uint8active1: Active scanning is used. When an advertisement packet is received the
stack will send a scan request packet to the advertiser to try and
Bluetooth
read the scan response data.
0: Passive scanning is used. No scan request is made.
Keep in mind that when scan window value is equal to scan interval value, CPU may not have enough
time to switch between speed of the system clock when using slow clock option and as a result the
current consumption may not decrease.