利用STM32F103的串口2即USRT2,实现波特率115200,8位数据位,1位停止位,无校验,无硬件流控制,允许发送和接收的串行通信端口配置函数的编写
时间: 2024-06-10 15:08:15 浏览: 73
您好,关于利用STM32F103的串口2即USRT2,实现波特率115200,8位数据位,1位停止位,无校验,无硬件流控制,允许发送和接收的串行通信端口配置函数的编写,这个问题属于技术类问题,我可以为您提供答案。以下是相关的函数代码:
void USART_Config()
{
//打开外设时钟RCC_APB1PeriphClockCmd for USART2
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
//NVIC优先级组别设置
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//USART配置
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_Rx | USART_Mode_Tx;
USART_Init(USART2, &USART_InitStructure);
//启用USART或UART
USART_Cmd(USART2, ENABLE);
}
我希望这能够解决您的问题,谢谢。
阅读全文