Bus SBUS

Is a serial bus SBUS receiver output bus via the root, all channels available on the remote control. At present, many UAV model and electronic devices support access to bus SBUS. Data acquisition channel using the bus SBUS, high efficiency, and save hardware resources, only one line to acquire data for all channels.

Extended Information:

Bus SBUS using TTL level is the inverted level, i.e., standard TTL of 1 is the inverse 0, and 0 is the inverse 1, 100,000 baud rate, data bits of 8 bits, 2 stop bits , even parity.

SBUS a data length is 25 bytes, the first of which "0" bytes header: 0x0f; 24 bytes of the frame end: 0x00; from 1 byte to 22 bytes 1-16 byte ratio of data channels; 23 byte, bit 7 is the 17-channel digital switch channels, bit 6 channel 18 to the digital switch channels.

Bit 5 is the frame status flag (determined whether frame dropping), for controlling the state of the LED on the receiver, bit 4 is a failsafe activation flag This bit is 1, indicating that the receiver enters failsafe state.


 


 

1, Introduction
SBUS is essentially a serial communication protocol, the baud rate of 100K, 8 data bits, two stop bits, even efficacy, i.e. 8E2 of serial communication.

It is worth noting three points:

1.SBUS using negative logic, so that regardless of the reception or transmission hardware to be negated (note, the hardware must be inverted), the circuit is as follows

This is a circuit I see when looking for information online, in fact, I use the following circuit

2.SBUS has two modes,

      . A high-speed mode: sent every 4ms

      . B low speed: sent every 14ms

   That is 14ms intervals of 4 or 25 sends the serial data bytes, 25 bytes of data which may contain up to 16 information

3.100K baud rate is not standard baud rate, serial tools usually can not directly read (so do not use a computer to debug directly, unless you write non-standard PC serial port) can be read by the microcontroller.

 

2. The protocol specific format as follows:
        [header] [first byte] [Second byte] ...... [twenty-second byte] [flag] [Last Data]

Header, flag, the end does not carry data information, and the data head and tail are fixed data, header = 0x0f; tail data = 0x00; 

Data header (1 byte) + data (22 bytes) + flag (1 byte) + tail data (1 byte)

 

3. codec C language source 
coding theory

       A 11bit binary information, such as 11,111,111,111 can represent a message, a total of 16 such information, the information in the order of these 16 series of successively arranged, to obtain a data 176bit (11 * 16), i.e. 22 bytes (176/8 = 22) data, header data plus the parity bit on the end of a composed information to be transmitted through the serial port. Every 4 or 14ms to transmit such a message.

      16 so that the maximum value of each of the information can be represented is 2048 = 2 ^ 11, that is, his accuracy.

      Flag

      The high nibble flag has a special meaning, and the fourth did not use, according to my understanding, seventh and sixth represent two digital channels (channels 17 and 18) information (that is, only the high and low channels generally used to control the on-off or a simple motor start or stop, for example, 1 represents 0 for stopping the motor to start the motor), represents the fifth frame loss, receiver red LED lights up, my understanding is that if this one 1, the frame signal indicates a problem, the red LED lights receiver. The fourth bit indicates fault protection activation, meaning it should be said that if this bit is 1, activation of the recipient fault protection.

     bit7 = ch17 = digital channel (0x80)
     bit6 = ch18 = digital channel (0x40)
     bit5 = Frame lost, equivalent red LED on receiver (0x20)
     bit4 = failsafe activated (0x10)
     bit3 = n/a
     bit2 = n/a
     bit1 = n/a
     bit0 = n/a

  Decoded code
      buffer [] corresponding to the data received

       _channels [] corresponding to channel

_channels[0]  = ((buffer[1]|buffer[2]<<8)                      & 0x07FF);
_channels[1]  = ((buffer[2]>>3 |buffer[3]<<5)                 & 0x07FF);
_channels[2]  = ((buffer[3]>>6 |buffer[4]<<2 |buffer[5]<<10)  & 0x07FF);
_channels[3]  = ((buffer[5]>>1 |buffer[6]<<7)                 & 0x07FF);
_channels[4]  = ((buffer[6]>>4 |buffer[7]<<4)                 & 0x07FF);
_channels[5]  = ((buffer[7]>>7 |buffer[8]<<1 |buffer[9]<<9)   & 0x07FF);
_channels[6]  = ((buffer[9]>>2 |buffer[10]<<6)                & 0x07FF);
_channels[7]  = ((buffer[10]>>5|buffer[11]<<3)                & 0x07FF);
_channels[8]  = ((buffer[12]   |buffer[13]<<8)                & 0x07FF);
_channels[9]  = ((buffer[13]>>3|buffer[14]<<5)                & 0x07FF);
_channels[10] = ((buffer[14]>>6|buffer[15]<<2|buffer[16]<<10) & 0x07FF);
_channels[11] = ((buffer[16]>>1|buffer[17]<<7)                & 0x07FF);
_channels[12] = ((buffer[17]>>4|buffer[18]<<4)                & 0x07FF);
_channels[13] = ((buffer[18]>>7|buffer[19]<<1|buffer[20]<<9)  & 0x07FF);
_channels[14] = ((buffer[20]>>2|buffer[21]<<6)                & 0x07FF);
_channels[15] = ((buffer[21]>>5|buffer[22]<<3)                & 0x07FF);
  编码代码
 
    // SBUS header
    packet[0] = 0x0F; 
    // 16 channels of 11 bit data
    packet[1]  = (unsigned char) ((channels[0] & 0x07FF));
    packet[2]  = (unsigned char) ((channels[0] & 0x07FF)>>8   | (channels[1] & 0x07FF)<<3);
    packet[3]  = (unsigned char) ((channels[1] & 0x07FF)>>5   | (channels[2] & 0x07FF)<<6);
    packet[4]  = (unsigned char) ((channels[2] & 0x07FF)>>2);
    packet[5]  = (unsigned char) ((channels[2] & 0x07FF)>>10  | (channels[3] & 0x07FF)<<1);
    packet[6]  = (unsigned char) ((channels[3] & 0x07FF)>>7   | (channels[4] & 0x07FF)<<4);
    packet[7]  = (unsigned char) ((channels[4] & 0x07FF)>>4   | (channels[5] & 0x07FF)<<7);
    packet[8]  = (unsigned char) ((channels[5] & 0x07FF)>>1);
    packet[9]  = (unsigned char) ((channels[5] & 0x07FF)>>9   | (channels[6] & 0x07FF)<<2);
    packet[10] = (unsigned char) ((channels[6] & 0x07FF)>>6   | (channels[7] & 0x07FF)<<5);
    packet[11] = (unsigned char) ((channels[7] & 0x07FF)>>3);
    packet[12] = (unsigned char) ((channels[8] & 0x07FF));
    packet[13] = (unsigned char) ((channels[8] & 0x07FF)>>8   | (channels[9] & 0x07FF)<<3);
    packet[14] = (unsigned char) ((channels[9] & 0x07FF)>>5   | (channels[10] & 0x07FF)<<6);  
    packet[15] = (unsigned char) ((channels[10] & 0x07FF)>>2);
    packet[16] = (unsigned char) ((channels[10] & 0x07FF)>>10 | (channels[11] & 0x07FF)<<1);
    packet[17] = (unsigned char) ((channels[11] & 0x07FF)>>7  | (channels[12] & 0x07FF)<<4);
    packet[18] = (unsigned char) ((channels[12] & 0x07FF)>>4  | (channels[13] & 0x07FF)<<7);
    packet[19] = (unsigned char) ((channels[13] & 0x07FF)>>1);
    packet[20] = (unsigned char) ((channels[13] & 0x07FF)>>9  | (channels[14] & 0x07FF)<<2);
    packet[21] = (unsigned char) ((channels[14] & 0x07FF)>>6  | (channels[15] & 0x07FF)<<5);
    packet[22] = (unsigned char) ((channels[15] & 0x07FF)>>3);
    // flags
    packet[23] = 0x00;
    // footer
    packet[24] = 0X00;
 


 

 

 

Published 136 original articles · won praise 71 · views 160 000 +

Guess you like

Origin blog.csdn.net/u012308586/article/details/104925207