STM32串口通信发送脚配置问题
void uart_init3(u32 bound){
/*串口3初始化*/
//GPIO端口设置
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3|RCC_APB2Periph_GPIOB, ENABLE); //使能USART3,GPIOB时钟
//USART3_TX GPIOB.10
//GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //PB.10
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
//GPIO_Init(GPIOB, &GPIO_InitStructure);//初始化GPIOB.10
//USART3_RX GPIOB.11
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;//PB.11
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //浮空输入或上拉输入
GPIO_Init(GPIOB, &GPIO_InitStructure); //初始化GPIOB.11
//Usart3 NVIC 配置
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=6;//抢占优先级7
NVIC_InitStructure.NVIC_IRQChannelSubPriority =0; //子优先级0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化NVIC寄存器
//USART3 初始化设置
USART_InitStructure.USART_BaudRate = bound;//串口波特率
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_Rx | USART_Mode_Tx; //收发模式
USART_Init(USART3, &USART_InitStructure); //初始化串口3
USART_ITConfig(USART3, USART_IT_IDLE, ENABLE);//开启串口3空闲中断
USART_Cmd(USART3, ENABLE); //使能串口3
/*如下语句解决第1个字节无法正确发送出去的问题 */
USART_ClearFlag(USART3,USART_FLAG_TC);
}
如代码,串口3的PB10(发送脚)没有配置(注释掉),为什么串口通信还能工作?疑惑 不是芯片忘了开光了就是代码忘了开光了 ibmx311 发表于 2021-12-12 13:32
不是芯片忘了开光了就是代码忘了开光了
不好意思,是我弄错了。代码其他地方做了初始化
页:
[1]