STM32F030C8T6串口1与串口2配置后串口1使用不了

2019-07-14 14:24发布

单独配置串口1和串口2使用没问题,但是一旦配置两个之后串口1就使用不了了? 管脚映射正常,不清楚哪里出现问题,望高手出招。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
18条回答
jiusi66702
2019-07-15 08:06
void USART_INIT(void)
{
                GPIO_InitTypeDef  GPIO_InitStructure;
                USART_InitTypeDef USART_InitStructure;
                NVIC_InitTypeDef         NVIC_InitStructure;
       
                NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
                NVIC_InitStructure.NVIC_IRQChannelPriority = 2;
                NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
                NVIC_Init(&NVIC_InitStructure);
       
                GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_1);
                GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_1);
                GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_10;
                GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
                GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
                GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
                GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
                GPIO_Init(GPIOA, &GPIO_InitStructure);
       
                RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE );       
                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(USART1, &USART_InitStructure);
                USART_Cmd(USART1, ENABLE);
}
void USART2_INIT(void)
{
                GPIO_InitTypeDef GPIO_InitStructure;
                USART_InitTypeDef USART_InitStructure;
                NVIC_InitTypeDef         NVIC_InitStructure;
       
                NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
                NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
                NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
                NVIC_Init(&NVIC_InitStructure);
       
                GPIO_PinAFConfig(GPIOA,GPIO_PinSource2,GPIO_AF_1);
                GPIO_PinAFConfig(GPIOA,GPIO_PinSource3,GPIO_AF_1);
                GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3;
                GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
                GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
                GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
                GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
                GPIO_Init(GPIOA, &GPIO_InitStructure);
       
                RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE );       
                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_Cmd(USART2, ENABLE);
}

in main(void)
{
        USART_INIT();
        USART2_INIT();
        Delay(25000);
        USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
       
        USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);
}

一周热门 更多>