当前位置:网站首页>[stm32 HAL库] 串口通信
[stm32 HAL库] 串口通信
2022-06-28 23:05:00 【おもいね】
1.cubemx配置串口通信

Mode :
- Asynchronous : 异步, 整个过程,不会阻碍发送者的工作。
- Synchronous : 同步, 同步信息一旦发送,发送者必须等到应答,才能继续后续的行
为。 - Single Wire : 单总线, 半双工。

波特率和一些奇偶校验位的设置,发送和接收设置一样就ok。
2.串口代码的使用
我一般使用printf函数进行串口输出
重定向fputc函数
int fputc (int ch , FILE *f){
uint8_t temp[1] = {
ch};
HAL_UART_Transmit(&huart1,temp,1,2);
return ch;
}


3. 编写函数代码
//发送数据
HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData,
uint16_t Size, uint32_t Timeout);
//接收数据
HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData,
uint16_t Size, uint32_t Timeout);
//发送中断
HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *
pData, uint16_t Size);
//接收中断
HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData
, uint16_t Size);
//使用DMA发送
HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *
pData, uint16_t Size);
//使用DMA接收
HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *
pData, uint16_t Size);
//DMA暂停
HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart);
//DMA恢复
HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart);
//DMA停止
HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart);
边栏推荐
- 网上办理股票开户安全性高吗?
- FANUC机器人_KAREL编程入门(2)_通用IO信号的使用方法
- Didn't find an internship. He summed it up
- Online linear programming: Dual convergence, new algorithms, and regret bounds
- 【kotlin】好看的弹出框、自定义弹出框(对话框)、扩展函数、菊花等待条、消息提示框
- 邂逅阿维塔 11:强产品力下久违的新鲜感
- Online sql to htmltable tool
- YuMinHong set up two funds funded by his hometown
- 月薪6万,互联网“降本增效”后,这类人开始被疯抢
- Redis+aop+ user defined annotation to realize flow restriction
猜你喜欢

Master the usage of const

Zadig + cave Iast: let safety dissolve in continuous delivery

Leetcode detailed explanation of stack type

How to analyze the trend chart of London gold market with the moving average

LeCun预言AGI:大模型和强化学习都是斜道!我的世界模型才是新路
![[Chapter 2 of word tutorial series] how to set the table on each page to have a header in word](/img/1a/8416d2c48bf1ddcc45e0c5d9acf242.png)
[Chapter 2 of word tutorial series] how to set the table on each page to have a header in word
![Leetcode 324 swing sort ii[sort double pointer] the leetcode path of heroding](/img/41/b8ba8d771b7224eac1cc8c54fe9d29.png)
Leetcode 324 swing sort ii[sort double pointer] the leetcode path of heroding

见丰知夏|国漫鼻祖丰子恺,数字藏品独家发售

如何使用伦敦金画出支撑阻力线

Encounter with avita 11: long lost freshness under strong product power
随机推荐
如何使用伦敦金画出支撑阻力线
【深度学习】(3) Transformer 中的 Encoder 机制,附Pytorch完整代码
强大的开源API接口可视化管理平台-YApi
YuMinHong set up two funds funded by his hometown
Leetcode 324 Swing sort II [tri double pointeur] le chemin du leetcode pour l'héroding
[gateway development] handle the IP address segment represented by CIDR when NGX nested Lua
O & M troubleshooting - use hcache plug-in to troubleshoot excessive buffer/cache occupancy
超级工厂里的生意图鉴
CPU、GPU、TPU、NPU区别
手机办理股票开户安全性高吗?
直击产业落地 | 飞桨重磅推出业界首个模型选型工具
油猴脚本学习
见丰知夏|国漫鼻祖丰子恺,数字藏品独家发售
Explanation: Luogu p1762 even number /6.21 internal examination T2
Sample code of using redis to realize the like function
Detailed steps for MySQL to recover data through IBD files
运维排查-使用hcache插件排查Buffer/cache占用过高
[chapter 71 of the flutter problem series] mutual conversion between uint8list and image in flutter
CIN at QT (the clearest tutorial in the whole network)
论文解读(DCN)《Towards K-means-friendly Spaces: Simultaneous Deep Learning and Clustering》