求助!串口2中断接收的问题,收不到数据

2019-07-20 22:16发布

void USART2_Config(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
        USART_InitTypeDef USART_InitStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
       
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
        USART_DeInit(USART2);
       
        USART2_IRQHandler();
                /* USART2 ê1óÃIO¶Ë¿úÅäÖà */   
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //¸′óÃíÆíìêä3ö
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
  GPIO_Init(GPIOA, &GPIO_InitStructure);   

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;        //¸¡¿Õêäèë
  GPIO_Init(GPIOA, &GPIO_InitStructure);   //3õê¼»ˉGPIOA
          
        /* USART2 1¤×÷Ä£ê½ÅäÖà */
        USART_InitStructure.USART_BaudRate = 115200;        //2¨ìØÂêéèÖão115200
        USART_InitStructure.USART_WordLength = USART_WordLength_8b;        //êy¾YλêyéèÖão8λ
        USART_InitStructure.USART_StopBits = USART_StopBits_1;         //í£Ö1λéèÖão1λ
        USART_InitStructure.USART_Parity = USART_Parity_No ;  //êÇ·ñÆæżD£Ñé£oÎT
        USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;        //ó2¼tá÷¿ØÖÆÄ£ê½éèÖãoûóDê1Äü
        USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;//½óêÕóë·¢Ëí¶¼ê1Äü
        USART_Init(USART2, &USART_InitStructure);  //3õê¼»ˉUSART2
       
       
        USART_Cmd(USART2, ENABLE);// USART2ê1Äü
        USART_ITConfig(USART2,USART_FLAG_RXNE,ENABLE);
       
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_3);
        NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
        NVIC_Init(&NVIC_InitStructure);
}
void USART2_IRQHandler(void)
{
        u8 ch;
        if(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) != RESET)
        {
                ch=USART_ReceiveData(USART2);
                UART2SendByte(ch);
                Rx_buf[rev_count++]=ch;
        }
}
大家帮忙看看哪边配置的不对,小弟是新手


友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。