SBUS Protocol
What is SBUS
SBUS is a bus protocol for receivers to send commands to servos. It works sort of similarly to UART, SBUS uses a single serial line to provide the 16 channels of control command. (That is it transmits the control signal for 16 different attributes such as pitch, yaw, roll, flight mode..)
There are two different types of SBUS receivers that you can find on the market. The only difference between them is the way they use voltage to represent data. The two types are:
Futaba - THE SBUS we are usually referring to, also the person’s name who developed this protocol. Futaba uses an inverted standard way to represent the digital signal, with high voltage to represent logical-low and low voltage to represent logical-high.
Frsky - uses the standard way to represent the digital signal, with high voltage to represent logical-high and low voltage to represent logical-low. The mirror image of Futaba.
How to deal with inverted UART in STM32?
I believe most of the stm32 chips provide users with the option to invert the input/output from UART.
Take stm32 f5 as an example, look into its .ioc file, we can see the parameter set to the UART we configured.
Connectivity → the UART we are dealing with → Configuration → Parameter Setting → Advanced Features → TX/RX Pin Activitive Level Inversion → enable the option
In this way, the MCU is able to recognize the Futaba SBUS from UART input.
Configuration
baud rate: 100,000 (not any of the standard baud rates)
each uart frame has the config
1 start bit
8 data bits
1 even parity bit
2 stop bits
25 frames in a packet
1*start byte - 0x0F for data read
22 * data byte - 16 RC channels encoded on 22 bytes
1 * flag byte - contains 2 data channels(channel 17 & 18 ), with failsafe flag, and frame_lost flag
1 * end byte - 0x00 to indicate an end to the message
A parity check is a process in network communication to ensure the data transmission is accurate.
Even parity means that, for a given set of bits, the occurrences of 1 is counted. If the count is odd, the parity bit value is set to 1. If the count is even, the parity bit value is set to 0. In this way, the whole set including the parity but should give a count of 1 occurrences to be an even number. If not, we know something is going wrong with this packet of data.
Data Frame
Knowing what SBUS is for and how what an SBUS frame looks like, let’s take a look at how SBUS uses its 25 bytes to deliver 16 channels of data.
Suppose each byte is composed of 8 bits with IDs as follows [7 6 5 4 3 2 1 0] where bit 0 is the least significant bit. Then, if we probe the SBUS signal with an oscilloscope can see the following data as the least significant bit is transmitted first.
11110000 | CHANNEL1.0 CHANNEL1.1 CHANNEL1.2 CHANNEL1.3 CHANNEL1.4 CHANNEL1.5
CHANNEL1.6 CHANNEL1.7 | CHANNEL1.8 CHANNEL1.9 CHANNEL1.10 CHANNEL2.0 CHANNEL2.1
CHANNEL2.2 CHANNEL2.3 CHANNEL2.4 | CHANNEL2.5 CHANNEL2.6 CHANNEL2.7 CHANNEL2.8
CHANNEL2.9 CHANNEL2.10 CHANNEL3.0 CHANNEL3.1 | CHANNEL3. 2 CHANNEL3.3 ...
... CHANNEL16.10 | CHANNEL17.0 CHANNEL18.0 frame_lost failsafe 0 0 0 0 | 00000000
The 16 channels are each presented with 11 bits. The bits that cannot fit inside the byte will be concatenated at the least significant bits of the next bytes.
However, the least significant bit is stored at the rightmost bit in a byte. Therefore, the data byte will look like this:
Start Byte: [00001111b](0x0F)
Data Byte 0:[ch1.7 ch1.6 ch1.5 ch1.4 ch1.3 ch1.2 ch1.1 ch1.0]
Data Byte 1:[ch2.4 ch2.3 ch2.2 ch2.1 ch2.0 ch1.10 ch1.9 ch1.8]
Data Byte 2:[ch3.1 ch3.0 ch2.10 ch2.9 ch2.8 ch2.7 ch2.6 ch2.5]
Data Byte 3: ...
Flag Byte: [0 0 0 0 failsafe frame_lost ch18 ch17]
End Byte: [00000000](0x00)
Each of the 16 channels uses values in the range of 192 - 1792 which are mapped linearly in the Betaflight Firmware to values in the range of 1000 - 2000.
[192 - 1792] → [1000 - 2000]
Reference & Useful Links
https://github.com/bolderflight/SBUS
SBUS RC PROTOCOL HOW IT WORKS - Futaba Vs Frsky Inverted Complete Overview
Protocol decoder:sbus_futaba - sigrok
https://www.ibm.com/docs/en/aix/7.2?topic=parameters-parity-bits
SBUS to PPM decoder: https://www.ordinoscope.net/index.php/Electronique/Protocoles/SBUS
Futaba SBUS (more electrical related): https://os.mbed.com/users/Digixx/notebook/futaba-s-bus-controlled-by-mbed/
Futaba SBUS Driver: https://os.mbed.com/users/Digixx/code/SBUS-Library_16channel/file/83e415034198/FutabaSBUS/FutabaSBUS.cpp/