1. 基本配置
串口波特率:100k,9位数据位,偶校验,2位停止位,利用dma空闲中断进行接收数据和处理数据


接收函数
int8_t BSP_UART_IDLE_PollData(UART_HandleTypeDef *huart, struct RF207S_SBUS_DataStructure *rf207_sbus_data)
{
int8_t nret = 0;
if (Uart_Receive_Data.rxok == 0) //没有接收完就退出
{
nret = -1;
}
else
{
if (Uart_Receive_Data.rxlen < 25) //帧不完整
{
nret = -2;
}
else if (Uart_Receive_Data.rxbuf[0] != 0x0f || Uart_Receive_Data.rxbuf[24] != 0x00) //帧错误
{
nret = -3;
}
if (nret == 0)
{
//遥控器的取值范围:-100 ---->100 返回值的范围0----100
// Min:354 Max:1696 ----->1342 chx-353/1342. == y*100
rf207_sbus_data->ch1 = (((int16_t) Uart_Receive_Data.rxbuf[2] << 8) + ((int16_t) Uart_Receive_Data.rxbuf[1])) & 0x07ff;
rf207_sbus_data->ch1 = (rf207_sbus_data->ch1-353)

该文介绍了一个基于STM32的串口配置,使用100k波特率,9位数据位,偶校验和2位停止位。通过DMA空闲中断来接收和处理SBus数据。接收函数检查帧完整性并转换遥控器通道数据。空闲中断函数用于停止DMA接收并更新接收状态。
最低0.47元/天 解锁文章
4110

被折叠的 条评论
为什么被折叠?



