当前位置:网站首页>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);
}
}
边栏推荐
- MPPT太阳能充放电控制器数据采集-通过网关采集电池电压容量电量SOC,wifi传输
- 加密公司向盗窃的黑客提供报价:保留一点,把剩下的归还
- 什么是系统?
- The difference between link and @import
- 【Bank Series Phase 1】People's Bank of China
- 12 Disk related commands
- AtCoder Beginner Contest 261 Partial Solution
- 10、Redis实现点赞(Set)和获取总点赞数
- Chapter 9 SVM Practice
- The modification is not properly placed in the sandbox, causing Apple compatibility issues
猜你喜欢
随机推荐
什么是分布式锁?实现分布式锁的三种方式
Pythagorean tuple od js
Huawei od dice js
12 磁盘相关命令
The difference between link and @import
JetPack component Databinding
What is distributed and clustered?What is the difference?
你们程序员为什么不靠自己的项目谋生?而必须为其他人打工?
Maximum area of solar panel od js
开题报告之论文框架
C#远程调试
Multilingual settings of php website (IP address distinguishes domestic and foreign)
Installation of mysql5.7.37 under CentOS7 [perfect solution]
YOLOV5学习笔记(三)——网络模块详解
What is a distributed lock?Three ways of implementing distributed lock
Unity3D Button mouse hover enter and mouse hover exit button events
Unity3D Button 鼠标悬浮进入与鼠标悬浮退出按钮事件
直播预告 | KDD2022博士论文奖冠亚军对话
print task sorting js od huawei
加密公司向盗窃的黑客提供报价:保留一点,把剩下的归还