当前位置:网站首页>[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);
边栏推荐
- torch. nn. Transformer import failed
- With the development of industrial Internet as the starting point, the industry can enter a new stage of development
- 【深度学习】(2) Transformer 网络解析,代码复现,附Pytorch完整代码
- 运维排查-使用hcache插件排查Buffer/cache占用过高
- FANUC机器人_KAREL编程入门(2)_通用IO信号的使用方法
- Google Earth engine (GEE) -- crop extraction and analysis using sentinel-2 data
- Zadig + cave Iast: let safety dissolve in continuous delivery
- 没找到实习,他总结了这些
- C语言-单词分析解析
- Master the usage of const
猜你喜欢

Leetcode detailed explanation of stack type

一张能卖上千万,商家扩张比玩家还快:球星卡的江湖你不懂

在线SQL转HTMLTable工具

邂逅阿维塔 11:强产品力下久违的新鲜感

老家出资,俞敏洪设立两支基金

【Word 教程系列第 2 篇】Word 中如何设置每页的表格都有表头

【深度学习】(3) Transformer 中的 Encoder 机制,附Pytorch完整代码

第四章 存储器管理练习
![[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 擺動排序 II[排序 雙指針] HERODING的LeetCode之路](/img/41/b8ba8d771b7224eac1cc8c54fe9d29.png)
LeetCode 324 擺動排序 II[排序 雙指針] HERODING的LeetCode之路
随机推荐
Is it safe and reliable to open a securities account in changtou school?
O & M troubleshooting - use hcache plug-in to troubleshoot excessive buffer/cache occupancy
Google Earth Engine(GEE)——利用sentinel-2数据进行农作物提取分析
复杂嵌套的对象池(4)——管理多类实例和多阶段实例的对象池
见丰知夏|国漫鼻祖丰子恺,数字藏品独家发售
超级工厂里的生意图鉴
LeCun预言AGI:大模型和强化学习都是斜道!我的世界模型才是新路
【kotlin】好看的弹出框、自定义弹出框(对话框)、扩展函数、菊花等待条、消息提示框
网上办理股票开户安全性高吗?
Understand shell script in one article
[kotlin] beautiful pop-up box, custom pop-up box (dialog box), extension function, chrysanthemum waiting bar, message prompt box
This simple little function saves 213 hours for our production research team in half a year
Online text filter less than specified length tool
Code example of hiredis
Undefined symbol main (referred from entry9a.o).
Realization of 2D code generation in micro build low code
Cs5463 code module analysis (including download link)
FANUC机器人_KAREL编程入门(2)_通用IO信号的使用方法
直击产业落地 | 飞桨重磅推出业界首个模型选型工具
Qtcreater5.15.0 source code compilation process record