串口接收一次数据之后不能接收第二次

2019-07-20 10:12发布

用的F3的板子,在调试串口的时候,串口的发送是没问题的,但是在接收数据的时候,第一次接收也是正确的,但是之后再接收的时候,程序在“while (USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);”一直循环,走不出去,也就读不了数据了,程序也没办法接着走下去。请问有没有大佬遇到过这种问题,可以帮忙解决一下,万分感谢!!!


串口初始化如下:
void USART_Config(void)
{
  USART_InitTypeDef USART_InitStructure;
  GPIO_InitTypeDef GPIO_InitStructure;
USART_ClockInitTypeDef USART_ClockInitStruct;

  /* Enable GPIOB clock */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB , ENABLE);

  /* Enable USART1 APB clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

  /* USART2 Pins configuration **************************************************/
  //GPIO_DeInit(GPIOB);

  /* Configure pins as AF pushpull */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//GPIO_PuPd_NOPULL;//GPIO_PuPd_UP                                                                                
  GPIO_Init(GPIOB, &GPIO_InitStructure);         
        
   /* Connect pin to Periph */
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_7);   
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_7);

  USART_DeInit(USART1);
  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 enable */
  USART_Cmd(USART1, ENABLE);                                                                                                        
        
        
        
    /*·······串口时钟配置·············******************************/
  USART_ClockStructInit(&USART_ClockInitStruct);
USART_ClockInit(USART1,&USART_ClockInitStruct);        


}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
20条回答
一条咸鱼
2019-07-21 14:45
feichangkunge 发表于 2017-12-28 10:44
我觉得你应该把接收那部分的程序发出来

这是我后来写的接收中断的程序,麻烦您看一下,谢谢。

void USART1_IRQHandler (void)
{
  uint8_t ucTemp;
        //USART_ClearITPendingBit(USART1,USART_IT_RXNE);
        if(USART_GetITStatus(DEBUG_USARTx,USART_IT_RXNE)!=RESET)
        {               
                USART_ClearITPendingBit(USART1,USART_IT_RXNE);
                ucTemp = USART_ReceiveData(DEBUG_USARTx);
    USART_SendData(DEBUG_USARTx,ucTemp);   
        }         
}

一周热门 更多>