最近用STM32F042F6P用于双串口通信,串口1通信正常,串口2一直调试不成功,不知道是什么问题,故求助大神们;串口2的配置信息如下: void RCC_Configuration(void) { RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);//设置A端口时钟使能 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);//设置B端口时钟使能 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOF, ENABLE);//设置F端口时钟使能 RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); //设置串口1时钟使能 RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);//设置串口2时钟使能 } void USART2_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; //gpio配置 /* Connect PXx to USARTx_Tx */ GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_1);//PA2复用功能打开 /* Connect PXx to USARTx_Rx */ GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_1); //PA3复用功能打开 /* Configure USART2 Tx (PA.02) as alternate function push-pull */ GPIO_InitStructure.GPIO_Pin = USART2_TX; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Configure USART2 Rx (PA.3) as input mode */ GPIO_InitStructure.GPIO_Pin = USART2_RX; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); /* USART2 mode config */ USART_InitStructure.USART_BaudRate = 9600; 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_ITConfig(USART2,USART_IT_IDLE, ENABLE); //打开接收中断 USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); USART_Cmd(USART2, ENABLE); USART_ClearFlag(USART2, USART_FLAG_TC); //允许UART2中断 NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } void Uart2PutChar(unsigned char ch) { USART_SendData(USART2,ch); while(USART_GetFlagStatus(USART2,USART_FLAG_TXE)==RESET); } void Send2_Mesg(void) { Uart2PutChar('F'); Uart2PutChar('I'); Uart2PutChar('S'); Uart2PutChar('R'); Uart2PutChar('T'); Uart2PutChar('0'); Uart2PutChar('2'); Uart2PutChar('\n'); } |
【STM32F0开发日志/评测/笔记】+互补PWM波的产生
STM32F030 PB14和PB15无法输出PWM求助
【STM32F030探索套件】序列之五 外部中断
【STM32F0开发日志---二】+ucosii.2.92移植在STM32F030
上传个STM32F0+5110+内部温度传感器的菜鸟实例
【STM32F030探索套件使用问题】STM32F030 SPI方式驱动ST7565LCD失败
求一份STM32F051 I2C驱动LCD 12864的例程
STM32F0 M0 向结构体赋值进入HardFault异常
STM32F0 ADC-DMA方式采集2路数据时出现问题
STM32F030C8T6,TIM16定时慢很多问题?
评分
查看全部评分
评分
查看全部评分