Futaba S-BUS协议解析
来源:互联网 发布:php的面向对象编程 编辑:程序博客网 时间:2024/06/04 17:52
一、协议说明
S-BUS协议实际上通过串口进行数据发送。但是需要注意的是,S-BUS的逻辑电平是反的,需用如下电路对电平反相,再接到串口接收的管脚。
串口配置为波特率100kbps( 100000 ),8位数据,偶校验(even),2位停止位,无流控。
- 每帧25个字节,帧格式如下【参考https://mbed.org/users/Digixx/notebook/futaba-s-bus-controlled-by-mbed/】:
[Start Byte] [Data0] [Data1] …. [Data21] [Flags][End Byte]
两帧之间的时间间隔4ms(高速模式),约7ms一帧。
其中:
Start Byte = 0x0F。中间22个字节为16个通道的数据,每个通道用 11 bit表示,范围是0-2047。
End Byte根据S-BUS协议版本不同而不同。
Flags的定义:
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
数据部分:
如果把22个字节看作一个数的话,则数据部分采用小端模式。即若把数据按照[Data21][Data20]…[Data1][Data0]的顺序排列,则[Data21]的 bit 7 为MSB,[Data0]的 bit 0 为LSB,每 11 bit 为一个通道的数据。Data[21]和[Data20]的高3位为通道16的值,以此类推。
借用一张图,改了改:
下面是一组数据的例子(来自 R7008SB):
0F 01 04 20 A8 01 08 16 50 83 1A 80 00 04 20 00 01 08 07 38 00 10 80 00 04
0F 01 04 20 A8 01 08 16 50 83 1A 80 00 04 20 00 01 08 07 38 00 10 80 00 14
0F 01 04 20 A8 01 08 16 50 83 1A 80 00 04 20 00 01 08 07 38 00 10 80 00 24
0F 01 04 20 A8 01 08 16 50 83 1A 80 00 04 20 00 01 08 07 38 00 10 80 00 34
0F 01 04 20 A8 01 08 16 50 83 1A 80 00 04 20 00 01 08 07 38 00 10 80 00 04
0F 01 04 20 A8 01 08 16 50 83 1A 80 00 04 20 00 01 08 07 38 00 10 80 00 14
0F 01 04 20 A8 01 08 16 50 83 1A 80 00 04 20 00 01 08 07 38 00 10 80 00 24
0F 01 04 20 A8 01 08 16 50 83 1A 80 00 04 20 00 01 08 07 38 00 10 80 00 34
二、S-BUS解析程序
void Process(uint8_t* raw,uint16_t* result){ uint8_t bitsToRead=3; // bitsToRead表示需要从下一个字节中读取多少bit。规律:bitsToRead 每次总是增加 3 uint8_t bitsToShift; uint8_t startByte=21; uint8_t channelId=15; do { result[channelId]=raw[startByte]; if(bitsToRead<=8) { result[channelId]<<=bitsToRead; bitsToShift=8-bitsToRead; result[channlId]+=(raw[startByte-1]>>bitsToShift); } else { result[channelId]<<=8; result[channelId]+=raw[startByte-1]; startByte--; bitsToRead-=8; bitsToShift=8-bitsToRead; result[channelId]+=(raw[startByte-1]>>bitsToShift); } result[channelId]&=0x7FF; channelId++; startByte--; bitsToRead+=3; }while(startByte>0); }
感谢来自
taogashi【http://www.eefocus.com/taogashi/blog/14-05/303577_f140d.html】
以及
Uwe Gartmann【https://developer.mbed.org/users/Digixx/notebook/futaba-s-bus-controlled-by-mbed/】
的有关S-BUS协议的介绍。
0 0
- Futaba S-BUS协议解析
- STM32 解析futaba S-bus协议
- Futaba SBUS协议解析
- Futaba S-BUS controlled by mbed(使用mbed控制Futaba S-BUS)
- GPRS协议,MODBUS协议及M-BUS协议格式解析
- Mod-bus协议数据结构
- forum | futaba
- Bus Error解析
- usb 协议分析 -bus hound
- Meter Bus解析1:概述
- Meter Bus解析5:UC3842
- can/bus通讯协议技术原理
- USB协议中的建立事务 bus hound
- bus
- BUS
- bus
- Meter Bus解析2:slave设计
- Meter Bus解析6:主机设计实例
- stm32 GPIO电气特性
- php中使用fsockopen实现异步请求
- 为什么用static来修饰方法或者变量?用处?
- Jupyter中直接显示Matplotlib的图形
- JqueryDataTable的使用
- Futaba S-BUS协议解析
- [Leetcode,python] Majority Element 众数
- Atitit java onvif 开源类库 getProfiles getStreamUri
- Spring boot(12) 整合富文本编辑器kindeditor 以及代码优化
- Xcode8.1下搭建 Python环境
- CSS高级布局样式技巧
- SQL高级数据过滤
- Xamarin android使用Sqlite做本地存储数据库
- Intent要使用的ACTION都有哪些?在哪里能查到详细的ACTION呢?