波特率:约定的传输速率,1000bps,1s发1000位
引脚
结构
数据帧的传输特点
代码:
#include "stm32f10x.h" // Device header
#include "Delay.h"
#include "OLED.h"GPIO_InitTypeDef GPIO_InitStruct;
USART_InitTypeDef USART_InitStruture;void Serial_Init(void){RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);//开启USART1的时钟RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);//开启GPIOA的时钟GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;//复用推挽输出GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9;//TXGPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(GPIOA, &GPIO_InitStruct);//初始化USARTUSART_InitStruture.USART_BaudRate = 9600;//波特率USART_InitStruture.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//不使用USART_InitStruture.USART_Mode = USART_Mode_Tx;//需要发送功能USART_InitStruture.USART_Parity = USART_Parity_No;//不需要校验位USART_InitStruture.USART_StopBits = USART_StopBits_1;//停止位1USART_InitStruture.USART_WordLength = USART_WordLength_8b;//八位字长USART_Init(USART1, &USART_InitStruture);USART_Cmd(USART1, ENABLE);
}void Serial_SendByte(uint8_t Byte){USART_SendData(USART1, Byte);//传递数据至TDRwhile(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);//等待TDR数据传送完
}int main(void){Serial_Init();Serial_SendByte(0x41);while(1){}
}
效果: