stm32f7网口_STM32F7xx —— 串口通信
一、串口初始化过程
1、时钟使能;
2、GPIO初始化;
3、串口波特率设置;
4、串口控制;
5、数据发送与接收
二、几个重要的串口函数
HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart); // 串口初始化
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_UART_ENABLE_IT(__HANDLE__, __INTERRUPT__) // 串口中断使能
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority); // 设置中断优先级
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn); // 使能中断
三、几个重要的结构
// 串口初始化结构体 包含了串口句柄 波特率配置 发送接收缓存 dma等
// 我们只描述前两个基本功能,对效率要求极高可以使用DMA。
typedef struct
{
USART_TypeDef *Instance; /*!< UART registers base address */
UART_InitTypeDef Init; /*!< UART communication parameters */
UART_AdvFeatureInitTypeDef AdvancedInit; /*!< UART Advanced Features initialization parameters */
uint8_t *pTxBuffPtr; /*!< Pointer to UART Tx transfer Buffer */
uint16_t TxXferSize; /*!< UART Tx Transfer size */
uint16_t TxXferCount; /*!< UART Tx Transfer Counter */
uint8_t *pRxBuffPtr; /*!< Pointer to UART Rx transfer Buffer */
uint16_t RxXferSize; /*!< UART Rx Transfer size */
uint16_t RxXferCount; /*!< UART Rx Transfer Counter */
uint16_t Mask; /*!< UART Rx RDR register mask */
DMA_HandleTypeDef *hdmatx; /*!< UART Tx DMA Handle parameters */
DMA_HandleTypeDef *hdmarx; /*!< UART Rx DMA Handle parameters */
HAL_LockTypeDef Lock; /*!< Locking object */
__IO HAL_UART_StateTypeDef gState; /*!< UART state information related to global Handle management
and also related to Tx operations.
This parameter can be a value of @ref HAL_UART_StateTypeDef */
__IO HAL_UART_StateTypeDef RxState; /*!< UART state information related to Rx operations.
This parameter can be a value of @ref HAL_UART_StateTypeDef */
__IO uint32_t ErrorCode; /*!< UART Error code */
}UART_HandleTypeDef;
// 串口的操作句柄 如 USART1 USART2 USART3等
typedef struct
{
__IO uint32_t CR1; /*!< USART Control register 1, Address offset: 0x00 */
__IO uint32_t CR2; /*!< USART Control register 2, Address offset: 0x04 */
__IO uint32_t CR3; /*!< USART Control register 3, Address offset: 0x08 */
__IO uint32_t BRR; /*!< USART Baud rate register, Address offset: 0x0C */
__IO uint32_t GTPR; /*!< USART Guard time and prescaler register, Address offset: 0x10 */
__IO uint32_t RTOR; /*!< USART Receiver Time Out register, Address offset: 0x14 */
__IO uint32_t RQR; /*!< USART Request register, Address offset: 0x18 */
__IO uint32_t ISR; /*!< USART Interrupt and status register, Address offset: 0x1C */
__IO uint32_t ICR; /*!< USART Interrupt flag Clear register, Address offset: 0x20 */
__IO uint32_t RDR; /*!< USART Receive Data register, Address offset: 0x24 */
__IO uint32_t TDR; /*!< USART Transmit Data register, Address offset: 0x28 */
} USART_TypeDef;
// 设置串口的各个参数 波特率 字长 停止位 奇偶校验 收发模式 硬件流 过采样
// 字长:8位/9位
// 停止位:1位/2位
typedef struct
{
uint32_t BaudRate; /*!< This member configures the UART communication baud rate.
The baud rate register is computed using the following formula:
- If oversampling is 16 or in LIN mode,
Baud Rate Register = ((PCLKx) / ((huart->Init.BaudRate)))
- If oversampling is 8,
Baud Rate Register[15:4] = ((2 * PCLKx) / ((huart->Init.BaudRate)))[15:4]
Baud Rate Register[3] = 0
Baud Rate Register[2:0] = (((2 * PCLKx) / ((huart->Init.BaudRate)))[3:0]) >> 1 */
uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
This parameter can be a value of @ref UARTEx_Word_Length */
uint32_t StopBits; /*!< Specifies the number of stop bits transmitted.
This parameter can be a value of @ref UART_Stop_Bits */
uint32_t Parity; /*!< Specifies the parity mode.
This parameter can be a value of @ref UART_Parity
@note When parity is enabled, the computed parity is inserted
at the MSB position of the transmitted data (9th bit when
the word length is set to 9 data bits; 8th bit when the
[1] [2] [3]
stm32f7网口_STM32F7xx —— 串口通信相关推荐
- stm32f7网口_STM32F7串口通信问题
STM32F7串口通信问题 所属分类:STM32F系列 浏览数:4572 提问者:dlx6969 提问时间:2018-02-07 问: STM32F767用到2个串口:串口1,230400,DMA发送 ...
- C#松下PLC通信源代码,支持松下Mewtocol协议,支持网口通信和串口通信,部分代码稍作修改后可直接copy到自己的上位机软件使用
C#松下PLC通信源代码,支持松下Mewtocol协议,支持网口通信和串口通信,部分代码稍作修改后可直接copy到自己的上位机软件使用 主要功能: 1.支持I/O实时监控,可自由改变要监控的I/O 2 ...
- 串口通信与网口通信简介
串口通信 串口通信介绍: 是指外设和计算机间,通过数据信号线 .地线.控制线等,按位进行传输数据的一种通讯方式. 这种通信方式使用的数据线少,在远距离通信中可以节约通信成本,但其传输速度比并行传输低. ...
- 串口通信Serial
基础知识 ASCII 表 | 菜鸟教程 (runoob.com) hex取值范围:不同编码有不同的解码范围,超过范围则无法解码 串口通信分类 一.并行通信 8位数据同时通过并行线进行传送,传输速率较高 ...
- 【QT Creator学习记录】(一)上位机与下位机串口通信
QT实现串口通信步骤以及问题记录,小白文,大佬轻锤,欢迎指错. [串口通信参考文章]这篇更为详细,部分代码是从这扒的 下面是UI界面,主要需求:通过串口或网口方式收发数据,读取下位机状态以及对其进行控 ...
- TQ2440(ARM)和SIM300(GPRS模块)串口通信
TQ2440(ARM)和SIM300(GPRS模块)串口通信 三月 15th, 2012 Linux平台开发 • 毕业论文 • 编程技术 1 Comment 最近在做串口通信这快遇到了很大的麻烦.现在 ...
- 2021-05-06PLC选型和串口通信
200Smart和1500.1200区别? S7200smart(国内)和S7 1200(国外),两者定位都是小型的PLC,大型为1500 Smart 是为了一些简单的很小的设备,为了降低成本准备.2 ...
- plc串口通讯 qt_Qt 串口通信之使用三菱PLC控制程序
作者:billy 版权声明:著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处 前言 上位机与PLC通信有很多种方式,比如CPU编程口.网口.串口.总线连接等等.本章节记录一下如何通过 ...
- android 平板串口调试,实验六:FSPAD_702平板串口通信实验
[实验内容] 基于FSPAD_702平板,实现串口通信. [实验目的] 熟悉FSPAD_702平板串口通信的整体流程. [实验环境] Ubuntu 10.04虚拟机,FSPAD_702开源平板,usb ...
- 自己用C#写的控制三菱FX5U PLC(三菱任何系列都通用,网口,串口都行)的上位机程序
自己用C#写的控制三菱FX5U PLC(三菱任何系列都通用,网口,串口都行)的上位机程序,PLC源程序也附上,是学习C#和三菱PLC通信的好例子,有对辅助继电器M,对单字,双子D的读写,IO的监控,报 ...
最新文章
- hexo博客更新主题后上传Git操作
- 苹果Think Different广告
- swift--添加新手引导页
- IT项目之旅(二)篮球计分器(分析、设计、实现)
- 《Spring Cloud Netflix官方文档》2. 服务发现:Eureka服务器
- PPT 下载 | 神策数据孙超赟:多场景解读运营的价值、生存状态与解决方案
- synchronized锁的升级
- leetcode869. 重新排序得到 2 的幂
- iis6 配置python CGI
- greenplum 查询出来的数字加减日期_POLA宝丽美白精华怎么查看生产日期保质期?保质期时间是几年的?查批号在哪里查?...
- 第一序列任小粟的能力_末世废土文—《第一序列》:“这世间,已经不需要齐天大圣了。”...
- 【数据库】MySql分割字符串
- Kate:Linux下自动检测文件编码的编辑器
- DPDK框架原理简介(0003转)
- MapReduce编程模型简介和总结
- 最齐全的装饰贴图素材,速来收藏
- ADS学习笔记—3.仿真实例
- 概率论与数理统计在计算机知识的应用,概率论与数理统计在生活中的应用 (5)...
- (超详细)搜索软件Everything的安装与使用
- 免费wiki系统php,HDWiki