STM32F103RBT6串口3配置不成功啥问题
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了STM32F103RBT6串口3配置不成功啥问题相关的知识,希望对你有一定的参考价值。
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
/*************************************************
函数: void GPIO_Config(void)
功能: GPIO配置
**************************************************/
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);
//
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;; //浮空输入
// GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //tx
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; //复用输出
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用输出
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; //rx
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;; //浮空输入
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; //复用输出
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //复用输出
GPIO_Init(GPIOB, &GPIO_InitStructure);
void NVIC_Configuration(void)
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); //设置中断优先级
NVIC_InitStructure.NVIC_IRQChannel =USART3_IRQChannel; //中断通道
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //强占优先级
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;//次优先级
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //通道中断使能
NVIC_Init(&NVIC_InitStructure);//初始化中断
void USART3_Config(void)
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate = 115200; //波特率
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //8位数据
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_Mode_Rx; //发送使能 接收
USART_Init(USART3,&USART_InitStructure);
USART_ITConfig(USART3,USART_IT_RXNE,ENABLE);
USART_ITConfig(USART3, USART_IT_IDLE, ENABLE);//开启超时中断
USART_Cmd(USART3, ENABLE);
USART_ClearFlag(USART3,USART_FLAG_TC);
以上是关于STM32F103RBT6串口3配置不成功啥问题的主要内容,如果未能解决你的问题,请参考以下文章