1、简介
SBUS,全称Serial Bus,即串行通信总线。本质上是一种串口通信协议,采用100K的波特率,8位数据位,2位停止位,偶效验,即串口通信。
2、串口配置
100k波特率,8位数据位(在stm32中要选择9位),偶校验(EVEN),2位停止位,无控流,25个字节。
3、协议格式
[startbyte] [data1] [data2] … [data22] [flags] [endbyte]
0x0f 0x00
4.sbus协议要加硬件取反电路
5.软件处理数据
struct sbus_s {
// 176 bits of data (11 bits per channel * 16 channels) = 22 bytes.
unsigned int chan0 : 11;
unsigned int chan1 : 11;
unsigned int chan2 : 11;
unsigned int chan3 : 11;
unsigned int chan4 : 11;
unsigned int chan5 : 11;
unsigned int chan6 : 11;
unsigned int chan7 : 11;
unsigned int chan8 : 11;
unsigned int chan9 : 11;
unsigned int chan10 : 11;
unsigned int chan11 : 11;
unsigned int chan12 : 11;
unsigned int chan13 : 11;
unsigned int chan14 : 11;
unsigned int chan15 : 11;
} __attribute__ ((__packed__));
typedef struct sbus_s sbus_data;
typedef struct
{
uint16_t ch[16];
} CRSFCHANNELS;
CRSFCHANNELS output_data_1;
uint8_t dmabuff_data[DMABUFFSIZE];
/*SBUS协议数据处理*/
void SbusData_Deal()
{
const sbus_data* const rcChannels =
(sbus_data*)&dmabuff_data[1];
output_data_1.ch[0] = rcChannels->chan0&0x07FF;
output_data_1.ch[1] = rcChannels->chan1&0x07FF;
output_data_1.ch[2] = rcChannels->chan2&0x07FF;
output_data_1.ch[3] = rcChannels->chan3&0x07FF;
output_data_1.ch[4] = rcChannels->chan4&0x07FF;
output_data_1.ch[5] = rcChannels->chan5&0x07FF;
output_data_1.ch[6] = rcChannels->chan6&0x07FF;
output_data_1.ch[7] = rcChannels->chan7&0x07FF;
output_data_1.ch[8] = rcChannels->chan8&0x07FF;
output_data_1.ch[9] = rcChannels->chan9&0x07FF;
output_data_1.ch[10] = rcChannels->chan10&0x07FF;
output_data_1.ch[11] = rcChannels->chan11&0x07FF;
output_data_1.ch[12] = rcChannels->chan12&0x07FF;
output_data_1.ch[13] = rcChannels->chan13&0x07FF;
output_data_1.ch[14] = rcChannels->chan14&0x07FF;
output_data_1.ch[15] = rcChannels->chan15&0x07FF;
for(int i=0;i<6;i++)
printf("ch[%d]=%d\r\n",i,output_data_1.ch[i]);
printf("\r\r\r\r\r");
}