当前位置:网站首页>STM32问题合集
STM32问题合集
2022-07-31 02:56:00 【yyhnet.cn】
Keil下载程序闪退
删除当前目录下的.uvoptx
后缀文件,重新配置魔法棒即可
HAL库串口中断不调用
STM32采用HAL库HAL_UART_Receive_IT()
只调用一次,首先要开启全局中断,然后确保在串口初始化完成后调用HAL_UART_Receive_IT()
确定返回HAL_OK
,再接收中断回调函数中添加,并且确保接收字节长度为1,因为采用HAL库,中断方式接收串口,只有当RxXferCount == 0 时,也就是调用这个函数,接收指定量的数据大小完成时,才会调用回调函数HAL_UART_RxCpltCallback()。所以紧接着,在串口中断服务函数里,又调用了一次,继续接收,这样就不会造成接收完指定的的数据帧长度就不会进入中断了。
uint8_t uart1_rxbuf[10];
uint8_t uart2_rxbuf[10];
if(HAL_UART_Receive_IT(&huart1, uart1_rxbuf, 1)==HAL_OK)
{
HAL_UART_Transmit(&huart1, (uint8_t *)"ok", 2,0xffff);
}
if(HAL_UART_Receive_IT(&huart2, uart2_rxbuf, 1)==HAL_OK)
{
HAL_UART_Transmit(&huart2, (uint8_t *)"ok", 2,0xffff);
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if(huart->Instance == USART1)
{
HAL_UART_Transmit(&huart2, uart1_rxbuf, 1,0xffff); // 把收到的字节原样发送出去
HAL_UART_Receive_IT(&huart1, uart1_rxbuf, 1); // 重新注册一次,要不然下次收不到了
}
if(huart->Instance == USART2)
{
HAL_UART_Transmit(&huart1, uart2_rxbuf, 1,0xffff);
HAL_UART_Receive_IT(&huart2, uart2_rxbuf, 1);
}
}
边栏推荐
- CMOS和TTL的区别?
- YOLOV5学习笔记(三)——网络模块详解
- 编译Hudi
- 11. Redis implements follow, unfollow, and follow and follower lists
- 5. SAP ABAP OData 服务如何支持 $filter (过滤)操作
- Unity3D Button mouse hover enter and mouse hover exit button events
- Intel's software and hardware optimization empowers Neusoft to accelerate the arrival of the era of smart medical care
- MPPT solar charge controller data collection - through the gateway acquisition capacity battery SOC battery voltage, wi-fi
- AI software development process in medical imaging field
- LeetCode Daily Question 2022/7/25-2022/7/31
猜你喜欢
7. List of private messages
Project (5) - Small target detection tph-yolov5
CMOS和TTL的区别?
LeetCode 1161 The largest element in the layer and the LeetCode road of [BFS binary tree] HERODING
STM32CUBEMX develops GD32F303 (11) ---- ADC scans multiple channels in DMA mode
CorelDRAW2022 streamlined Asia Pacific new features in detail
Word/Excel fixed table size, when filling in the content, the table does not change with the cell content
5. SAP ABAP OData 服务如何支持 $filter (过滤)操作
完整复制虚拟机原理(云计算)
YOLOV5学习笔记(三)——网络模块详解
随机推荐
开题报告之论文框架
Local area network computer hardware information collection tool
7、私信列表
StringJoiner in detail
LeetCode 1161 最大层内元素和[BFS 二叉树] HERODING的LeetCode之路
经典链表OJ强训题——快慢双指针高效解法
Unity3D Button 鼠标悬浮进入与鼠标悬浮退出按钮事件
学习DAVID数据库(1)
11. Redis implements follow, unfollow, and follow and follower lists
【Bank Series Phase 1】People's Bank of China
Chapter 9 SVM Practice
BAT卖不动「医疗云」:医院逃离、山头林立、行有行规
刚出道“一战成名”,安全、舒适一个不落
execsnoop 工具
Mysql 45讲学习笔记(二十三)MYSQL怎么保证数据不丢
基于opencv实现人脸检测
12 磁盘相关命令
AI中的数学思想
CefSharp入门-winform
华为分布式存储FusionStorage知识点总结【面试篇】