没有合适的资源?快使用搜索试试~ 我知道了~
STM32USART串口单片机发送数据
1星 需积分: 47 61 下载量 189 浏览量
2015-10-12
20:12:30
上传
评论 2
收藏 2KB TXT 举报
温馨提示
试读
2页
非常详细的介绍了如何使用STM32的串口USART发送数据,还附带非常完整的程序。
资源推荐
资源详情
资源评论
#include "stm32f10x.h"
int TXBuf1[4]={0x1234,0x2345,0x3456,0x4567}; //定义需发送的字符串
int i;
int main(void)
{
GPIO_InitTypeDef GPIO_InitStructure; //声明串口结构,由于串口即GPIO,所以同时声明GPIO
USART_InitTypeDef USART_Initstucture;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA, ENABLE); //使能PA端口时钟
// USART_StructInit(&USART_Initstucture); //串口结构成员设置
USART_Initstucture.USART_BaudRate = 9600;
USART_Initstucture.USART_WordLength = USART_WordLength_8b;
USART_Initstucture.USART_StopBits = USART_StopBits_1;
USART_Initstucture.USART_Parity = USART_Parity_No ;
USART_Initstucture.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Initstucture.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
// GPIO_StructInit(&GPIO_InitStructure); //GPIO结构成员设置
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed= GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
USART_Init(USART1,&USART_Initstucture); //初始化串口
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE); //初始化发送中断使能
USART_ITConfig(USART1,USART_IT_TXE,ENABLE); //初始化接收中断使能
int TXBuf1[4]={0x1234,0x2345,0x3456,0x4567}; //定义需发送的字符串
int i;
int main(void)
{
GPIO_InitTypeDef GPIO_InitStructure; //声明串口结构,由于串口即GPIO,所以同时声明GPIO
USART_InitTypeDef USART_Initstucture;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA, ENABLE); //使能PA端口时钟
// USART_StructInit(&USART_Initstucture); //串口结构成员设置
USART_Initstucture.USART_BaudRate = 9600;
USART_Initstucture.USART_WordLength = USART_WordLength_8b;
USART_Initstucture.USART_StopBits = USART_StopBits_1;
USART_Initstucture.USART_Parity = USART_Parity_No ;
USART_Initstucture.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Initstucture.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
// GPIO_StructInit(&GPIO_InitStructure); //GPIO结构成员设置
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed= GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
USART_Init(USART1,&USART_Initstucture); //初始化串口
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE); //初始化发送中断使能
USART_ITConfig(USART1,USART_IT_TXE,ENABLE); //初始化接收中断使能
资源评论
- 晨7142021-03-14骗积分的,就一个初始哈而已,有什么用,甚至连中断都没有
kms720
- 粉丝: 1
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功