我STM32F401的官方板子跑串口程序为何无现象啊,程序如下

2019-07-21 05:00发布

void COM2Init(u32 BaudRate)
{
   GPIO_InitTypeDef GPIO_InitStructure;
   USART_InitTypeDef USART_InitStructure;
  
   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); 
   RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
   GPIO_PinAFConfig(GPIOD, GPIO_PinSource2, GPIO_AF_USART2);  
   GPIO_PinAFConfig(GPIOD, GPIO_PinSource3, GPIO_AF_USART2);
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
   GPIO_Init(GPIOA, &GPIO_InitStructure);    
   USART_InitStructure.USART_BaudRate = BaudRate;//波特率设置
   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_Cmd(USART2, ENABLE);//开启串口
   USART_ClearFlag(USART2, USART_FLAG_TC);
}
调用的USART_SendData(USART2,9);发送数据
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。