当前位置:网站首页>A serial port data receiving mode of stm32
A serial port data receiving mode of stm32
2022-04-22 16:38:00 【Meishan swordsman】
Project requirements control 12 Circuit solenoid valve , Control frame format of solenoid valve Header frame 0xFB , Data bits xxx, Tail frame 0xFB. The following implementation is made in the serial port interrupt callback function .
uint8_t start_Flag=0;// Data start flag bit
uint8_t cont=0;// Data count digit
uint8_t RX_Buff[16];// Data caching
uint8_t flash_Fiag=0;// Data acceptance complete
// Serial interrupt callback function
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if(huart->Instance==USART1)
{
if(temp==0xFB)// Start frame
{
start_Flag=1;
RX_Buff[cont++]=temp;
}
else if(temp==0xBF)// End frame
{
start_Flag=0;
RX_Buff[cont]=temp;
flash_Fiag=1;
cont=0;
}
else// Process frame
{
if(start_Flag==1)
{
RX_Buff[cont++]=temp;
if(cont>=16)// Data overflow detection
{
start_Flag=0;
}
}
}
}
HAL_UART_Receive_IT(huart,&temp,1);// You need to turn on the receive interrupt at the end of each reception
}
Clear accept buffer data
void clean_RX_Data(void)
{
for(int i=0;i<16;i++)
{
RX_Buff[i]=0;
}
}
Main circulation while(1) Add the following functions to the , After improvement, a timer can be used to receive data , Every time 50ms Receive primary data .
if(flash_Fiag==1)// A timer can be used to detect data acceptance If the data is accepted
{
flash_Fiag=0;
for(int i=0;i<16;i++)
{
final_Data[i]=RX_Buff[i];
}
clean_RX_Data();
}
Experimental phenomena : Apollo F429 test , Send header and footer , The returned data is consistent with the sent data .

Project development : On this basis , You can go directly through final_Data[i] Make corresponding control judgment on the array elements in the !!!
版权声明
本文为[Meishan swordsman]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221637180802.html
边栏推荐
- Huawei machine test questions -- hj54 expression evaluation
- 华为机试题——HJ60 查找组成一个偶数最接近的两个素数
- 接口测试 Mock 实战(二) | 结合 jq 完成批量化的手工 Mock
- TM of NLP: Based on gensim library, call 20newsgr to learn doc topic distribution and save it as train SVM LDA txt、test-svm-lda. txt
- 坚持做正确的事情
- Talk about the general problem of substitution between TL431 and az431 (personal experience)
- 如何登录MySQL
- 蓝桥杯练习020
- 蓝桥杯练习016
- i.MX6ULL驱动开发 | 21 - 按键驱动使用 input 子系统上报事件
猜你喜欢

Hx711 weight sensor wiring

An analysis and treatment of abnormal growth of Oracle database table space

C ODBC loads the files of one folder into the blob column of Oracle database and downloads the blob column to another folder

wps excel 怎么复制工作表?(移动或复制工作表)

Summary of process and principle of solution to concurrency problem (form repeated submission problem)

Blue Bridge Cup practice 018

小练习:二分查找及实现

详述 CHARTEVENTS 检查记录表(十)

多线程使用redis进行累加结果不对解决方案

numpy基础大全(创建、索引、常用函数)
随机推荐
12.88万元的小魔驼2.0,毫末智行托起末端物流自动配送的商用梦想
蓝桥杯练习020
Blue Bridge Cup practice 017
Blue Bridge Cup practice 013
Blue Bridge Cup exercise 016
蓝桥杯练习011
多线程使用redis进行累加结果不对解决方案
In SolidWorks, why can I only set direction 1 but not direction 2 for linear sketch array?
RT-Thread Studio 对代码进行格式化
持续交付-Jenkinsfile 语法
SolidWorks insert socket head cap screw
蓝桥杯练习014
This API hub is powerful. It contains open APIs such as nailing enterprise wechat, and can be debugged directly!
国产手机品牌才发现,没有国内消费者支持它们什么也不是
小练习:二分查找及实现
HMS Core Discovery第14期回顾长文|纵享丝滑剪辑,释放视频创作力
ASEMI低压降肖特基二极管比普通肖特基好在哪?
C ODBC loads the files of one folder into the blob column of Oracle database and downloads the blob column to another folder
TM of NLP: Based on gensim library, call 20newsgr to learn doc topic distribution and save it as train SVM LDA txt、test-svm-lda. txt
对于现阶段GameFi发展而言,兼容EVM重要吗?