当前位置:网站首页>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);
}
}
边栏推荐
- Intel's software and hardware optimization empowers Neusoft to accelerate the arrival of the era of smart medical care
- 【银行系列第一期】中国人民银行
- Difference between CMOS and TTL?
- 局域网电脑硬件信息收集工具
- CefSharp入门-winform
- 关于 mysql8.0数据库中主键位id,使用replace插入id为0时,实际id插入后自增导致数据重复插入 的解决方法
- Uninstallation of mysql5.7.37 under CentOS7 [perfect solution]
- Project (5) - Small target detection tph-yolov5
- 数学解决——环形链表问题
- StringJoiner in detail
猜你喜欢
How to do a startup CTO?
YOLOV5学习笔记(二)——环境安装+运行+训练
LeetCode 1161 最大层内元素和[BFS 二叉树] HERODING的LeetCode之路
Chapter 9 SVM实践
YOLOV5 study notes (2) - environment installation + operation + training
Face detection based on opencv
10 Permission introduction
Installation, start and stop of redis7 under Linux
分布式与集群是什么 ? 区别是什么?
Discourse 自定义头部链接(Custom Header Links)
随机推荐
Maximum area of solar panel od js
医疗影像领域AI软件开发流程
[C language foundation] Solve C language error: expected ';', ',' or ')' before '&' token
f.grid_sample
The use of font compression artifact font-spider
8. Unified exception handling (controller notifies @ControllerAdvice global configuration class, @ExceptionHandler handles exceptions uniformly)
Local area network computer hardware information collection tool
开题报告之论文框架
Mysql 45讲学习笔记(二十四)MYSQL主从一致
Go 项目实战-获取多级分类下的全部商品
return in try-catch
AI software development process in medical imaging field
字体压缩神器font-spider的使用
Discussion on Service Commitment of Class Objects under Multithreading
execsnoop 工具
Office automation case: how to automatically generate period data?
CMOS和TTL的区别?
What is a distributed lock?Three ways of implementing distributed lock
【shell基础】判断目录是否为空
f.grid_sample