首页 > 编程知识 正文

sbc传输协议,sbe协议

时间:2023-05-03 10:51:16 阅读:177882 作者:1949

文章目录目录目录摘要1 .什么是1.sbus协议2 .解析2.STM32sbus协议2.1初始化串口接收2.2配置串行中断服务函数2.3sbus数据2.4任务下2.5相关变量的调用和定义3 .数据的获取

摘要

本节主要记录自己学习SBUS协议的过程,欢迎批评指正!!!这里参考下面这个博客:sbus协议分析

什么是SBUS协议SBUS是一个接收机串行总线输出,通过这根总线? 可以取得遥控器上所有频道的数据。 目前,许多模型和无人机电子设备都支持接入SBUS总线。 使用SBUS总线获取通道数据是高效的,节省了硬件资源,可以通过一根电缆获取所有通道的数据。

特点1:SBUS总线使用的是TTL级别的相反级别。 也就是说,标准TTL的1反转为0,0反转为1。 串行端口的波特率为100000,数据位为8位,2停止位,偶尔检查一下。 3358 www.Sina.com/: http://www.Sina.com/的长度为http://www.Sina.com /,其中第'0'个字节为http://www.Sina.com/: http://http://www.Sina.com/http://www.Sina.com /

特点2:SBUS为什么是16频道? 22x8=11x16,因此各通道用11bit表示,范围为0-2047。 两帧之间的时间间隔为4ms (高速模式),约7ms为一帧。

具体的SBUS介绍是参考官方网站信息SBUS一帧数据2. STM32来解析SBUS协议2.1,并参考串行端口接收voidsbus_init(uintbound )/gpiocmdybgg nvic _ inittypedefnvic _ init structure; RCC _ AP B1 periphclockcmd (RCC _ AP B1 per iph _ usar T3,ENABLE ); //usar T3RCC _ AP B2 periphclockcmd (RCC _ AP B2 per iph _ gpiob,ENABLE ); //gpiob//usar T3 _ rxgpiob.11 gpio _ init structure.gpio _ pin=gpio _ pin _ 11; //pb11 gpio _ init structure.gpio _ mode=gpio _ mode _ in _ floating; //gpio_init(gpiob,GPIO_InitStructure; //gpiob 11//usar T3 _ rxnvicnvic _ init structure.nvic _ IRQ channel=usar T3 _ irqn; nvic _ init structure.nvic _ irqchannelpreemptionpriority=3; //3n vic _ init structure.nvic _ irqchannelsubpriority=0;//0 nvic _ init structure.nvic _ irqchannelcmd=enable; //IRQ nvic _ init (nvic _ init structure; ///vic//usar T3usart _ init structure.usart _ baudrate=bound;//usart _ init structure.usart _ word length=usart _ word length _ 8b;//8 usart _ init structure.usart _ stop bits=usart _ stop bits _ 1; //usart _ init structure.usart _ parity=usart _ parity _ no;//usart _ init structure.usart _ hardware flow control=usart _ hardware flow control _ none;//usart _ init structure.usart _ mode=usart _ mode _ rx|usart _ mode _ tx; //USART_Init(usart3,usart_init

Structure); //³õʼ»¯´®¿Ú3 USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);//¿ªÆô´®¿Ú½ÓÊÜÖжÏUSART_ITConfig(USART3, USART_IT_IDLE, ENABLE); USART_Cmd(USART3, ENABLE); //ʹÄÜ´®¿Ú3} 2.2配置串口中断服务函数 void USART3_IRQHandler(void){uint8_t res;uint8_t clear = 0;static uint8_t Rx_Sta = 1;if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET){res =USART3->DR;USART3_RX_BUF[Rx_Sta++] = res;}else if(USART_GetITStatus(USART3, USART_IT_IDLE) != RESET){clear = USART3->SR;clear = USART3->DR;USART3_RX_BUF[0] = Rx_Sta - 1;Rx_Sta = 1;}} 2.3进行SBUS数据解析 void Sbus_Data_Count(uint8_t *buf){sbus_ch[ 0] = ((int16_t)buf[ 2] >> 0 | ((int16_t)buf[ 3] << 8 )) & 0x07FF;sbus_ch[ 1] = ((int16_t)buf[ 3] >> 3 | ((int16_t)buf[ 4] << 5 )) & 0x07FF;sbus_ch[ 2] = ((int16_t)buf[ 4] >> 6 | ((int16_t)buf[ 5] << 2 ) | (int16_t)buf[ 6] << 10 ) & 0x07FF;sbus_ch[ 3] = ((int16_t)buf[ 6] >> 1 | ((int16_t)buf[ 7] << 7 )) & 0x07FF;sbus_ch[ 4] = ((int16_t)buf[ 7] >> 4 | ((int16_t)buf[ 8] << 4 )) & 0x07FF;sbus_ch[ 5] = ((int16_t)buf[ 8] >> 7 | ((int16_t)buf[ 9] << 1 ) | (int16_t)buf[10] << 9 ) & 0x07FF;sbus_ch[ 6] = ((int16_t)buf[10] >> 2 | ((int16_t)buf[11] << 6 )) & 0x07FF;sbus_ch[ 7] = ((int16_t)buf[11] >> 5 | ((int16_t)buf[12] << 3 )) & 0x07FF;sbus_ch[ 8] = ((int16_t)buf[13] << 0 | ((int16_t)buf[14] << 8 )) & 0x07FF;sbus_ch[ 9] = ((int16_t)buf[14] >> 3 | ((int16_t)buf[15] << 5 )) & 0x07FF;sbus_ch[10] = ((int16_t)buf[15] >> 6 | ((int16_t)buf[16] << 2 ) | (int16_t)buf[17] << 10 ) & 0x07FF;sbus_ch[11] = ((int16_t)buf[17] >> 1 | ((int16_t)buf[18] << 7 )) & 0x07FF;sbus_ch[12] = ((int16_t)buf[18] >> 4 | ((int16_t)buf[19] << 4 )) & 0x07FF;sbus_ch[13] = ((int16_t)buf[19] >> 7 | ((int16_t)buf[20] << 1 ) | (int16_t)buf[21] << 9 ) & 0x07FF;sbus_ch[14] = ((int16_t)buf[21] >> 2 | ((int16_t)buf[22] << 6 )) & 0x07FF;sbus_ch[15] = ((int16_t)buf[22] >> 5 | ((int16_t)buf[23] << 3 )) & 0x07FF;} 2.4在任务中调用 void Loop_Task_5ms(void){Sbus_Data_Count(USART3_RX_BUF);} 2.5相关变量和定义 uint8_t USART3_RX_BUF[26];uint16_t sbus_ch[18]; //ͨµÀÊý¾Ýuint8_t sbus_rc_flag = 0; #ifndef __SBUS__H__#define __SBUS__H__#include "uart.h"extern uint8_t USART3_RX_BUF[26];extern uint16_t sbus_ch[18]; //ͨµÀÊý¾Ýextern uint8_t sbus_rc_flag ;void Sbus_Init(uint32_t bound);void Sbus_Data_Count(uint8_t *buf);#endif 3.获取数据


版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。