STM32 UART串口读取解析总结
参考这三篇博文
https://blog.csdn.net/sinat_16643223/article/details/119226462
https://blog.csdn.net/sinat_16643223/article/details/118830297
https://blog.csdn.net/sinat_16643223/article/details/119307624
方式两种:终端和查询
大部分是中断,用中断写法我看了两个STM32的读取解析程序,大体差不多,基本是卡一个字节处理一个字节,不像PC上对缓冲区一堆字节处理。写法参考这两篇博文里的代码。 对比下面两段代码是不是差不多。
https://blog.csdn.net/sinat_16643223/article/details/119307624
flow_decode.c
#include<stdint.h>
#include"flow_decode.h"
UpixelsOpticalFlow updata;
int16_t flow_parse_char(uint8_t ch)
{
int16_t ret = 1;
static int16_t s = 0, p = 0;
static uint8_t Xor_r = 0x00, Xor_c = 0x00;
switch(s)
{
case 0:
if(ch == 0xFE)
{
s = 1;
//printf("Got FE\n");
}
break;
case 1:
if(ch == 0x0A)
{
s = 2;
p = 0;
Xor_c = 0x00;
//printf("Got 0A\n");
}else
s = 0;
break;
case 2:
((char *)&updata)[p++] = ch;
Xor_c ^= ch;
if(p == 10){
s = 3;
p = 0;
}
break;
case 3: //crc
s = 4;
Xor_r = ch;
break;
case 4://end
if(ch == 0x55){
//printf("Got 0x55\n");
if(Xor_r == Xor_c){
ret = 0;
}
else
ret = 2;
}
s = 0;
break;
default:
break;
}
return ret;
}
https://blog.csdn.net/sinat_16643223/article/details/118830297
还有一个例程代码可以看我这篇博文,也是和上面差不多的写法,看来基本可以确定STM32的串口中断法读取解析基本是这种样式写了。
https://blog.csdn.net/sinat_16643223/article/details/119308734
ACfly的GPS数据的串口的解析也是这样的,注意有的传感器驱动不是这么写的因为不是基于UART串口的,而是IIC或者其他的。
这里也是用中断进行的STM32串口的收发,收到一个字节,就会产生一个接收中断。
https://blog.csdn.net/sinat_16643223/article/details/119380455
https://mp.weixin.qq.com/s/vTmFTYnK8QwtdwMCnHml0g
thoneflow也就是思码光光流模块的PX4串口驱动的解析函数的写法也是这个思路!!!!!!仔细看挺简单的,和STM32中断方式进行串口解析的写法一样。parser就是解析的意思。