Introduction to dry goods BLE: understanding BLE from the air data transmission and reception (part 1)

BLE is the abbreviation of Bluetooth Low Energy, that is, Bluetooth Low Energy, which is a subset of the Bluetooth specification and was introduced from the Bluetooth 4.0 version. BLE technology has successfully adapted to the needs of devices that require a small amount of wireless data transmission and are sensitive to power consumption in the Internet of Things era. At present, many MCU devices integrate the BLE wireless transceiver circuit on the chip, and also maintain the low power consumption characteristics of the MCU, and realize a single-chip IoT solution.

BLE is the abbreviation of Bluetooth Low Energy, that is, Bluetooth Low Energy, which is a subset of the Bluetooth specification and was introduced from the Bluetooth 4.0 version. BLE technology has successfully adapted to the needs of devices that require a small amount of wireless data transmission and are sensitive to power consumption in the Internet of Things era. At present, many MCU devices integrate the BLE wireless transceiver circuit on the chip, and also maintain the low power consumption characteristics of the MCU, and realize a single-chip IoT solution.

In recent years, through forum activities, I have been in touch with MCU products that support BLE from NXP, ST, TI, and ON Semi. I deeply feel that the threshold of BLE is not low. To design a work that makes full use of the advantages of BLE, it is necessary to have a more comprehensive understanding of this technology. Learning to understand BLE also requires a process. If you only modify the existing examples each time, the experience gained is very limited. What is the best starting point for learning? Maybe different people have different habits. I intend to provide some references from the perspective of MCU hardware engineers, and I have the idea of ​​this article.

The purpose of using BLE on the MCU is nothing more than sending data or receiving data. Why is it difficult to get started with BLE? The simplest in comparison: UART, SPI, and a little more complicated I2C, CAN these-they are all wired connections (nonsense), the sender has a separate (at least exclusive during transmission) and reliable (under normal circumstances, 1/0 will be sent, and 1/0 will be received) Data channel; and the host sends a request before the data is transferred, or the data itself has a request flag. Looking at BLE again, the data is sent out via radio waves, and the receiver has to determine whether there is a signal for itself in the radio waves received by the antenna, and then demodulate the data from the valid signal…The complexity is already incomparable. Although the wireless function module on the chip has done the modulation and demodulation work, its work instructions are still issued by the software. BLE uses radio waves to transmit information, which is to encode data and modulate it into a radio frequency signal for transmission. In layman’s terms, the radio frequency used by BLE is 2.4G, which is a concept of 2.4GHz used with Wi-Fi, wireless keyboard and mouse, and Zigbee, Thread and other protocols. So the question is, will these signals interfere with each other? First of all, it must be clear that the term 2.4GHz refers to a frequency band rather than a single frequency (the full name 2.4GHz Industry Science Medicine band), covering from 2400MHz to 2483.5MHz, is an open frequency band used for short distances without a license. It must also be clear: any signal transmission with information must occupy a certain bandwidth, and it cannot be a single frequency. A single frequency can only be a permanently constant sinusoidal signal-it cannot carry information. For example, the frequency referred to by radio broadcasting is the center frequency of its signal. AM (Amplitude Modulation) Voice of China at 639kHz, the actual signal bandwidth is twice that of its broadcast audio bandwidth.

BLE arranges 40 channels in this 2.4GHz frequency band, with a center frequency starting from 2402MHz with 2MHz intervals. As shown in the upper part of the figure below:

Introduction to dry goods BLE: understanding BLE from the air data transmission and reception (part 1)

The lower part of the above figure shows the frequency band occupied by the 2.4G Wi-Fi channel. Note that the different channel frequency bands of Wi-Fi are likely to overlap. The overall frequency coverage of Wi-Fi and BLE overlaps. As for whether different 2.4GHz wireless devices interfere with each other, it depends on the energy distribution of the actual communication waves: time is the first dimension, and frequency is the second dimension. As long as there is no overlap, there will be no interference; but even if it exists Partial overlap, non-serious interference does not damage the encoded data; the possibility of interference always exists, and various wireless protocols also need check and retransmission mechanisms to ensure data integrity. A BLE device can only select one of the 40 channels for transmission or monitoring at any one time. The carrier frequency that is transmitted or tried to monitor is the center frequency of the corresponding channel. The modulation method used by BLE is called GFSK, which is an improved form of FSK modulation. FSK (Frequency Shift Keying) is a simple modulation: it changes the output signal frequency from 2NThe two frequencies are selected and switched according to the modulation code. The simplest is 1-bit modulation, called 2-FSK (others are not discussed in this article), as shown in the figure below:

Introduction to dry goods BLE: understanding BLE from the air data transmission and reception (part 1)

The red line on the graph represents the encoded data, and the blue line is the output signal waveform. Note that the instantaneous frequency change of the modulated signal occurs at the moment when the code value changes. One application of FSK modulation is a modem used in audio telephone lines, which modulates two different tones with data bit streams in two directions, as shown in the figure below. At one end of the line, 1170Hz means 0 and 1270Hz means 1; on the other end of the line, 2025Hz means 0 and 2225Hz means 1.

Introduction to dry goods BLE: understanding BLE from the air data transmission and reception (part 1)

I wrote a MATLAB program to simulate such a modulated wave, and play the generated wav file from the computer to feel the frequency spectrum of FSK. FS=48000;Tt=10;t=0:FS*Tt-1;f_center=1170; %2125;f_shift=100;baud=300;pe0=2*pi/FS*(f_center-f_shift);pe1=2 *pi/FS*(f_center+f_shift); s=zeros(1,FS*Tt);c=s;p=0;enc_one=0;for k=1:FS*Tts(k) = 0.9*sin( p);c(k) = enc_one;if enc_onep = p+pe1;elsep = p+pe0;endif mod(k,round(FS/baud))==0 if rand>0.5, enc_one=0; else enc_one=1 ; endfprintf(‘%d’,enc_one);endendfprintf(‘n’);plot(t,s,t,0.5*c-1.5,’r’);set(gca,’YLim’,[-1.6 1]);wavwrite(s,48000,16,’fsktone.wav’); FFT analysis and drawing of the simulated modem FSK (300bits/s) modulated wave, the carrier with center frequency 1170Hz and 2125Hz are represented by different colors:

Introduction to dry goods BLE: understanding BLE from the air data transmission and reception (part 1)

The realization of FSK modulation is simple in that only one switch signal is needed to control the oscillator, allowing the oscillator to choose one of two operating frequencies, and the output is the FSK modulation wave. From the above spectrum analysis diagram, it can be seen that the section where the energy of the frequency components of the FSK output waveform is most concentrated also has a certain span, not just the “two frequencies” of the oscillator. The energy distribution gradually decreases after the distance from the center frequency is far, but it may still interfere with other signals. The GFSK modulation used by BLE, preceded by a G letter to represent Gaussian, is to let the signal waveform controlling the oscillator frequency pass through a Gaussian low-pass filter first, so that there is a smooth transition along the transition edge. In other words, although the GFSK modulator also has two basic oscillation frequencies, the switching process is smooth.

Introduction to dry goods BLE: understanding BLE from the air data transmission and reception (part 1)

Compared with FSK modulation, GFSK modulation improves the width of the frequency spectrum, that is, the utilization efficiency of the frequency band is improved. BLE uses GFSK modulation, and the basic data rate is 1Mbps, which means that if it continues to transmit, one million 0 or 1 can be sent in one second. The BLE 5.0 specification adds a 2Mbps option. Select one of the 40 channels, through GFSK, BLE can send a string of 0/1 to the air. Three of these 40 channels need to be taken out separately, the numbers are 37, 38, and 39. They are used for advertising. . The remaining 37 channels are used for communication after the connection is established. By the way, BLE and classic Bluetooth (common in Bluetooth speakers and earphones) are not compatible and cannot communicate with each other. BLE is not a simplified version of traditional Bluetooth, it is different in channel division, from the data format to the upper layer protocol. The mainstream smart phones now support both classic Bluetooth and BLE. We should pay attention to the distinction when referring to the Bluetooth concept. The data transmission of BLE is carried out in the unit of packet. A packet is a string of formatted 0 and 1, which is modulated by GFSK into a carrier on a certain channel, and then demodulated and restored by the receiver (among which In fact, there are two more steps called whitening and de-whitening, but without changing the data length and function, we will ignore them for the time being). As shown in the figure below, an original BLE data packet consists of 4 segments: the header is 8-bit Preamble, which is used for synchronization, then the 32-bit Access Address (see its function later), and then the payload of the data packet content , Followed by the 24-bit CRC check value at the end.

Introduction to dry goods BLE: understanding BLE from the air data transmission and reception (part 1)

The BLE device in the receiving state needs to monitor on the same channel before it is possible to receive this data packet. The receiver also needs to know the length of the data packet to perform the CRC check. The length of the packet is included in the PDU segment. The specific format of the PDU is different depending on the type of the packet. Channels 37, 38, and 39 are used for advertising. These are the three channels used by the BLE slave device to indicate its own existence, and are also used by the master device to scan and initiate a connection. In these three channels, the data packet format is as follows:

Introduction to dry goods BLE: understanding BLE from the air data transmission and reception (part 1)

There are 7 types of data packets in the Advertising channel, which are determined by the PDU Type field in the PDU header field. The packet length information is the Length field of the header field. According to the different package types, the content of Payload is also different. ADV_IND, ADV_NONCONN_IND, ADV_SCAN_IND and ADV_DIRECT_IND type packets are sent from the device at its own interval, where the AdvA data field is its own address (the BLE scanning tool on the mobile phone sees this address), and the AdvData data field provides other information For example, the device name, manufacturer code, etc., can also include self-defined information such as temperature sensor data. ADV_DIRECT_IND is a special type. It is used to initiate a connection to the designated master device without additional unnecessary data. After the ADV_IND and ADV_SCAN_IND packets are received by the master device, the master device can immediately send the SCAN_REQ packet to request the device to be scanned, and then the slave device will respond with the SCAN_RSP packet to provide supplementary data (ScanRspData). Only when the master device wants to initiate a connection, it will respond with a CONNECT_REQ packet to the packet sent by the slave device (only ADV_IND and ADV_DIRECT_IND types are valid). In this way, even if a connection is established between the master and slave devices, the next 37 channels will be used for information exchange. The advertising of the slave device just mentioned has its own interval, which is determined by the advInterval parameter in the BLE API (that is, the meaning of “broadcast once every time”). However, if the advInterval parameters of the two devices are exactly the same, it may happen to be broadcasting at the same time every time, which interferes with each other. In order to alleviate this problem, BLE stipulates that a random delay should be added to the interval between the actual two advertising events, as shown in the following figure:

Introduction to dry goods BLE: understanding BLE from the air data transmission and reception (part 1)

The shorter the interval here, the easier it is to discover the device if other conditions remain the same. Of course, the price paid is increased power consumption. As mentioned earlier, there are 3 channels for advertising. Usually, the master device will also listen on these three channels in turn. Therefore, an advertising event generally sends a data packet on each of the three channels. This can prevent a channel from being unusable if it is interfered (note that the frequencies of channels 37, 38, and 39 are not close). The following is a schematic diagram in which the host on channel 38 has performed a scan.

Introduction to dry goods BLE: understanding BLE from the air data transmission and reception (part 1)

Now I want to remind everyone: the BLE wireless part also consumes a lot of energy in the receiving (monitoring) state, not much less than in the transmitting state. Compared with the power consumption of the on-chip CPU, the wireless function of BLE is indeed a big power consumer. Manufacturers will regard the current during TX/RX as an important indicator of power saving capacity-the point is, the power consumption of RX cannot be ignored. As a slave device, it is necessary to turn on the wireless transmission function when performing an advertising event. During other intermittent periods (tens of milliseconds to a few seconds), the device can sleep and wait, so the average power consumption may be very low. But the master device wants to find the slave device, but it can’t sleep for a long time, because the slave device only transmits for a moment. If the master device does not monitor at that time, it will be missed. But the main device is always in the monitoring state (three channels in turn), and the wireless part consumes a lot of power. Usually the master device will also intermittently monitor to find the slave device, which is a strategy of continuing to receive for a period of time and then taking a break. If the slave device sets a very long broadcast interval in order to reduce its own power consumption, then the master device will have to pay more power consumption to discover it. BLE has to achieve low power consumption for both the master and the slave. The main points of BLE can be summarized as “meeting at the appointed time and place in advance.” In the advertising stage of the slave described above, the master cannot know which of the three channels the slave is broadcasting at which time, so the master has to take a stand-by approach, so the power consumption of the master cannot be as low as the slave. But the two are different after the BLE connection is established. Now review the Payload content of the CONNECT_REQ packet sent by the host to the slave in order to establish the connection:

In addition to the BLE addresses of the master and slave, the LLData part contains many fields:

AA: Access Address, used in the data channel data packet CRCInit: randomly generated initial value of CRC WinSize: Connection Event Transmit Window Size, in units of 1.25ms WinOffset: Same as above, the time offset of Transmit Window Interval: Interval of Connection Event Time Latency: Slave Latency parameter Timeout: connSupervisionTimeout parameter, in units of 10ms ChM: Mark the data channel to be used Hop: hopIncrement, which is the parameter of the frequency hopping algorithm SCA: The sleep clock error parameter of the host determines the BLE connection by the above fields Initial parameters. How does the slave know when the master will send data packets on which channel? Please see the picture below:

In fact, the host computer and the cluster computer have agreed on a future time window. The host computer will send the first data packet within that time window, and the slave computer needs to keep monitoring. Because the two parties have agreed on a time window, the time of the radio RX state can be shortened, and the power consumption is controlled. After the host sends a data packet, it turns to the receiving state. When the cluster machine receives the data packet from the host, it will quickly respond to a data packet. The two-way data exchange time can be predicted, and there is no useless RX waiting state. Then, the host sends out the data packet again at a time after a connection interval (connInterval), that is, a new connection event starts, but the communication channel is reselected by the adaptive frequency hopping algorithm. The above figure only draws the simplest state. In fact, a connection event can have multiple two-way data packet interactions. View the slave and master side by side:

Introduction to dry goods BLE: understanding BLE from the air data transmission and reception (part 1)

The above figure also shows a feature of the BLE connection status: slave latency, which allows the slave to not respond to some (maybe unreceived) data packets, while the connection can be maintained temporarily and continuously dropped. Because the time interval agreement between the two parties is still there, the communication can be resumed as long as the subsequent interaction is successful. The data packet format in the BLE connection state is not listed in this article, because it involves many contents of the Link Layer layer. Friends who want to know more can refer to the Bluetooth Core specification 4.0 and later version documents. The purpose of this article is to give you an overall impression of how the bottom layer of BLE works, and to realize how it achieves low-power wireless data interaction.

The Links:   https://www.slw-ele.com/skiip13ac12t4v1.html“> SKIIP 13AC12T4V1 LM130SS1T611

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *