stm32快速学习4——串口发送字符

本文介绍了一个简单的 STM32F10x 系列微控制器 UART1 发送功能的初始化过程。通过配置时钟、GPIO 和 USART 参数实现串口通信的基本设置,并发送字符“A”作为示例。

设定UART1时钟

设定发送脚功能

串口设置,使能

#include "stm32f10x.h"

void RCC_Configuration(void);

void GPIO_Configuration(void);

void USART_Configuration(void);

unsigned char str[]="A";

int main(void)

{

  RCC_Configuration();

  GPIO_Configuration();

  USART_Configuration();

  USART_SendData(USART1,str[0]);  

  while(1);

}

void RCC_Configuration(void)

{    

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

}

void GPIO_Configuration(void)

{

  GPIO_InitTypeDef GPIO_InitStructure;

  /*只设定了发送*/

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

}

void USART_Configuration(void)

{

  USART_InitTypeDef USART_InitStructure;

  USART_InitStructure.USART_BaudRate = 115200;

  USART_InitStructure.USART_WordLength = USART_WordLength_8b;

  USART_InitStructure.USART_StopBits = USART_StopBits_1;

  USART_InitStructure.USART_Parity = USART_Parity_No;

  USART_InitStructure.USART_HardwareFlowControl= USART_HardwareFlowControl_None;

  USART_InitStructure.USART_Mode = USART_Mode_Tx; /*只设定了发送*/

  USART_Init(USART1 , &USART_InitStructure);

  USART_Cmd(USART1, ENABLE);

}


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值