How to establish the connection between the master and slave devices of BLE module

Update:2017-07-12Views:231

In the process of low-power Bluetooth technology to establish connection, the devices come in pairs, master and slave devices. If the master wants to establish a connection with the slave, the master will need to initiate a connection request (CONNECT-REQ), so the master can be called as a connection initiator. At the same time, the slave must be connectable and capable of parsing CONNECT-REQ, and the slave can be called as a broadcaster.  The following is the frame structure of CONNECT-REQ.

Payload

InitA

(6 octets)

AdvA

(6 octets)

LLData

(22 octets)

InitA is the Bluetooth address of the connection initiator, and the length is 6 bytes; AdvA is the Bluetooth address of the broadcaster, and the length is 6 bytes; In addition to InitA and AdvA, the most important part of the frame format is LLData, and this part contains the meaningful parameters that need to be used during the process of connection establishment.

In order to better understand the CONNECT-REQ, we can find a similar example in our daily life to help us understand its meaning. Many readers should have work experience, and before starting a new job, you need to sign a labor contract with the employer. CONNECT_REQ is a "labor contract" provided by the "employer" master, and only need to confirmed by the “employee ” slave, this contract will come into effect. The connection of low-power Bluetooth technology also has been established. Next we will analyze the terms in the "contract" one by one (as shown in the following table).

LLData

AA

(4 octets)

CRCInit

(3 octets)

WinSize

(1 octets)

WinOffset

(2 octets)

Interval

(2 octets)

Latency

(2 octets)

Timeout

(2 octets)

ChM

(5 octets)

Hop

(5 bits)

SCA

(3 bits)

(1)    Access Address (AA):
The first clause of this contract is to assign a unique identification code within the company to the employee, similar to the badge number, and the employee can use this number within the company. When the employee leaves the company, the unique identification code will automatically become invalid. Even if the employee joins in the company again, his or her new badge number is different from the old one. Similarly, before a connection is established between the two low-power Bluetooth technology devices, the master device is responsible for generating the access address, and this address is similar to a 4-byte random number. When the connection is established, both master and slave use this access address to communicate. When the connection is disconnected, the access address is automatically disabled.

(2)    CRCInit (CRC Initial Value)
The second clause of this contract is CRCInit, which is just the employee’s key within the company. With this key, the employee can access the company's internal resources. For low-power Bluetooth technology devices, master and slave use CRCInit to verify the integrity of data packet.

(3)    WinSize and WinOffset
The third clause of the contract specifies the time when the employee will report for duty in the first time and how long he or she will work in the future. WinSize and WinOffset also made a similar definition in the connection of low-power Bluetooth technology. WinOffset defines the offset of a communication window after the CONNECT_REQ command, as shown in Figure 3. After the slave device receives CONNECT_REQ, the slave device takes some time to do some configuration according to the LLData parameter. Therefore, WinOffeset provides time for slave devices to do this operation, transmitWindowOffset= WinOffset×1.25 ms. WinSize defines the window time when the device turns on the transceiver each time, whether master or slave, they follow the definition of WinSize, window time transmitWindowSize=WinSize×1.25 ms. Therefore, after CONNECT_REQ, the first data frame sent by the master to the slave, we call it "anchor point" (as shown in Figure 3), because all subsequent connection events are based on this moment, showing in a cyclical change. From the red block diagram we can see that the first data frame can not be earlier than(1.25ms+transmitWindowOffset), also can not later than(1.25 ms + transmitWindowOffset + transmitWindowSize)

(4)    Interval, Latency & Timeout
In general, people’s working hours is from 9:00am to 5:00pm, five days a week. But in the connection mechanism of low-power Bluetooth technology, we have adopted a more flexible one, "flexible work system". For the flexible work system of the connection of low-power Bluetooth technology, there are three parameters needed to understand, Interval, Latency & Timeout. 

After the connection is established, the data interaction between the master and the slave can be called a connection event. The connInterval of the connection event is set by the interval parameter, connInterval= Interval×1.25 ms, and the connInterval is in the range of 7.5ms to 4s. Therefore, after the anchor point has been determined, the master and slave will interact with the data according to the time interval determined by connInterval, as shown in Figure 4.

However, for low-power Bluetooth technology, the feature of low power needs to be taken into consideration specially, and in the actual application, there is no need to generate connection events at every connInterval. So the introduction of Lantancy can effectively reduce the generation of connection events, connSlaveLatency= Latency. connSlaveLatency defines how many consecutive connection events that the slave device can ignore, and it does not need to monitor the data packets from the master in these ignored connection events. This also means that the slave device does not need to wake up and turn on the the RF receiver to monitor at the time when each connection event occurs, so it can effectively reduce the power consumption of the slave device. This is also an important reason why low-power Bluetooth technology can achieve its low power consumption.

The timeout parameter defines the length of the connection timeout, connSupervisionTimeout= Timeout×10 ms, and it is in the range of 100ms to 32s. Whether it is master or slave, after it receives a data frame, if you wait for a connSupervisionTimeout without the next arrival of a data frame, you can think that the connection has been disconnected. It is important to emphasize here that connSupervisionTimeout must be more than (1 + connSlaveLatency)× connInterval × 2, otherwise, even if the slave device is in the Lantency state, it will also be mistaken for the connection timeout, resulting in a wrong disconnection.

(5)    Chm & Hop
We all know that Bluetooth uses frequency hopping technology. After the connection is established, the master and slave devices need to use some 
mechanism to perform frequency hopping work on the pre-set channel map, and in accordance with the pre-set frequency hopping spans. The channel map comes from Chm parameter, and each hopping span comes from Hop parameter. Hop is an integer, and it is in the range of 5 to 16. The following formula provides the working way for frequency hopping.
fn+1 =(fn+ Hop)mod37
Mod is the remainder operation.
Low-power Bluetooth technology has 37 date channels, and the data channel index is 0-36. In last formula, fn is the current channel index, and fn+1 is the next channel index. The following is the frequency hopping chart when Hop = 13.

RF Channel(fn)

fn

fn+1

2404MHz

0

(0+13)mod37=13

2404MHz

13

(13+13)mod37=26

2404MHz

26

(26+13)mod37=2

 

 

ChM is the bit mask code for the available data channel map, with a length of 5 bytes and 40 bits. Since there are 37 data channels, only the lower than 37 bits are valid. If a bit of the bit mask is set to 1, it means that the data channel represented by this bit is available. If it is set to 0, it is not available. According to the formula of the frequency hopping and ChM, the frequency hopping can be adaptive. If the fn + 1 channel is marked as available in ChM, fn + 1 is used as the next hop channel; If the fn+1 channel is marked as unavailable in ChM, the next hop channel needs to be remapped for data communication on other available channels. Therefore, the above mechanisms ensure that low-power Bluetooth technology has a good anti-interference ability.

This article is from the Internet, for reference only!
SKYLAB now mainly research BLE Bluetooth modules, SKB360 can be used as the master, and also can be used as the slave, and still can be used as the master-slave integration. For more details, please click Bluetooth module SKB360.

May we suggest

Chatting
SKYLAB_sales