当前位置:网站首页>[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);
边栏推荐
- [deep learning] (3) encoder mechanism in transformer, complete pytoch code attached
- 如何使用伦敦金画出支撑阻力线
- [flutter issues Series title 71] Mutual Conversion between uint8list and Image in flutter
- 邂逅阿维塔 11:强产品力下久违的新鲜感
- O & M troubleshooting - use hcache plug-in to troubleshoot excessive buffer/cache occupancy
- Langage C - analyse des mots
- 在线文本过滤小于指定长度工具
- 一文搞懂shell脚本
- 生产环境sonarqube安装
- 论文解读(DCN)《Towards K-means-friendly Spaces: Simultaneous Deep Learning and Clustering》
猜你喜欢

Panxiaoming, senior vice president of IC nansha|amd and President of Greater China: process, architecture and platform optimization break through the computing boundary

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

Wechat red envelope cover making tutorial and use guide with link jump

CS5463代码模块解析(包含下载链接)
![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

On the necessity and solution of building a campus online teaching video convergence platform

Pytorch builds transformer to realize multivariable and multi step time series forecasting (load forecasting)

第三章 处理机调度练习

Progress of dbnn experiment

一张能卖上千万,商家扩张比玩家还快:球星卡的江湖你不懂
随机推荐
网上办理股票开户安全性高吗?
C language - word analysis
LeCun预言AGI:大模型和强化学习都是斜道!我的世界模型才是新路
Serious internal entanglement in the we media industry: where should the enterprise we media go
如何使用伦敦金画出支撑阻力线
深入虚拟内存(Virtual Memory,VM)
在线SQL转HTMLTable工具
他原来是这么刷题的!
Sample code of using redis to realize the like function
国盛证券开户是真的安全可靠吗
LINQ linked table query
Detailed steps for MySQL to recover data through IBD files
Lecun predicts AgI: big model and reinforcement learning are both ramps! My world model is the new way
浅析搭建校园在线教学视频汇聚平台的必要性及解决方案
SqlServer复习
Langage C - analyse des mots
第三章 处理机调度练习
两栏布局左边图片显示部分由右边内容高度决定
第二章 经典同步练习作业
Production environment sonarqube installation