没有合适的资源?快使用搜索试试~ 我知道了~
STM32的串口初始化及串口通讯,包括串口的中断数据收取和发送。 代码演示将收到的数据原样返回。
资源推荐
资源详情
资源评论
/************************************************************************
Function: The process of the USART
Author: JIMMY
Date: 2019/03/28
************************************************************************/
#include "usart_driver.h"
#include "bios.h"
#include "system.h"
/*******************************************************************************
* Function : Initial Of USART1
* Parameters: None
* Return : None
*******************************************************************************/
void USART1Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStruct;
NVIC_InitTypeDef NVIC_InitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
//USART1_GPIO_Configuration
USART_DeInit(USART1);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;// Configure USART1_Tx as push-pull
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
Function: The process of the USART
Author: JIMMY
Date: 2019/03/28
************************************************************************/
#include "usart_driver.h"
#include "bios.h"
#include "system.h"
/*******************************************************************************
* Function : Initial Of USART1
* Parameters: None
* Return : None
*******************************************************************************/
void USART1Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStruct;
NVIC_InitTypeDef NVIC_InitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
//USART1_GPIO_Configuration
USART_DeInit(USART1);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;// Configure USART1_Tx as push-pull
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;// Configure USART1_Rx as input floating
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//USART1 Parameters Configuration
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
USART_InitStruct.USART_BaudRate = 115200;
USART_InitStruct.USART_WordLength = USART_WordLength_8b;
USART_InitStruct.USART_StopBits = USART_StopBits_1;
USART_InitStruct.USART_Parity = USART_Parity_No;
USART_InitStruct.USART_Mode = USART_Mode_Rx|USART_Mode_Tx;
USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_Init(USART1,&USART_InitStruct);
//USART1 Interrupt Configuration
NVIC_InitStruct.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct);
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
USART_Cmd(USART1,ENABLE);
}
/*******************************************************************************
* Function : Initial Of USART2
* Parameters: None
* Return : None
*******************************************************************************/
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//USART1 Parameters Configuration
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
USART_InitStruct.USART_BaudRate = 115200;
USART_InitStruct.USART_WordLength = USART_WordLength_8b;
USART_InitStruct.USART_StopBits = USART_StopBits_1;
USART_InitStruct.USART_Parity = USART_Parity_No;
USART_InitStruct.USART_Mode = USART_Mode_Rx|USART_Mode_Tx;
USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_Init(USART1,&USART_InitStruct);
//USART1 Interrupt Configuration
NVIC_InitStruct.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct);
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
USART_Cmd(USART1,ENABLE);
}
/*******************************************************************************
* Function : Initial Of USART2
* Parameters: None
* Return : None
*******************************************************************************/
剩余7页未读,继续阅读
资源评论
JIMMYV587
- 粉丝: 13
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 小巧可用的dll 查看工具
- spring boot2 实现elasticsearch 增删改查实例elasticsearch-rest-high-leve
- 职业院校教师科研能力提升途径.rar
- 信息办公学校教务管理系统(jsp+servlet+javabean)-school
- python项目开发实战基于OpenCV-AI人脸识别签到打卡系统(PyQt5+SQLite3)(源码+数据集+说明文档)zip
- 嵌入式大作业基于Python的上海、杭州和南京的空气质量、温度、风和降水量数据可视化分析项目源代码+数据
- 已优化的NavicatPremium数据库连接工具
- nginx一键安装脚本
- Fortran语言项目案例:学习资源和实用指南
- 基于springboot整合shiro完整代码案例demo
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功