ble protocol tutorial
Bluetooth Low Energy (BLE) is a wireless communication protocol designed for short-range communication between devices. It is commonly used for applications such as wireless sensors, health devices, fitness trackers, and smart home devices. BLE operates on the 2.4 GHz ISM (Industrial, Scientific, and Medical) band and is known for its low power consumption.
Here is a technical overview of the BLE protocol:
- PHY Layer (Physical Layer):
- Frequency: BLE operates in the 2.4 GHz ISM band, divided into 40 channels spaced 2 MHz apart.
- Modulation: Gaussian Frequency Shift Keying (GFSK) is used for modulation, providing resilience to interference and maintaining low power consumption.
- Data Rates: BLE supports two data rates: 1 Mbps (for long-range communication) and 2 Mbps (for short-range communication).
- Link Layer:
- Channels: BLE uses a frequency-hopping spread spectrum technique, where devices hop between channels in a pseudo-random manner to avoid interference.
- Addressing: Devices in BLE communication have a 48-bit address. There are two types of addresses: public (static) and random (dynamic).
- Host Controller Interface (HCI):
- The Host Controller Interface provides a command interface between the host (application processor) and the Bluetooth controller (hardware responsible for implementing the BLE protocol).
- It allows the host to control and configure the Bluetooth controller and exchange data with connected devices.
- Generic Access Profile (GAP):
- GAP defines the roles of devices in a BLE network and includes modes such as Broadcaster, Observer, Peripheral, and Central.
- It manages the overall connection and discovery processes.
- Generic Attribute Profile (GATT):
- GATT is used to organize and describe the data transferred between devices.
- It defines a hierarchical data structure with services, characteristics, and descriptors.
- Services, Characteristics, and Descriptors:
- Service: Represents a collection of data and associated behaviors. Examples include the Battery Service, Heart Rate Service, etc.
- Characteristic: Represents a single data point with its properties and value.
- Descriptor: Provides additional information about a characteristic's value, such as user description or format.
- Advertisement and Connection:
- Devices in BLE communicate by advertising their presence. Advertising packets contain information about the device and its capabilities.
- Connection initiation involves scanning for devices, establishing a connection, and exchanging data.
- Security:
- BLE provides security features like encryption and authentication to ensure the confidentiality and integrity of data exchanged between devices.
- Profiles:
- BLE profiles define how a device behaves within a specific application. Common profiles include the Generic Attribute Profile (GATT) and services like the Heart Rate Service, Battery Service, etc.
- Application Layer:
- The application layer interacts with the GATT layer to read and write data from and to the connected devices.
- Application-specific logic is implemented at this layer based on the requirements of the BLE-enabled device.