AnsweredAssumed Answered

Problem with USART1 Interrupt

Question asked by lq.huong on May 15, 2014
Latest reply on May 16, 2014 by lq.huong
Hi all.
I have a problem with USART1 Interrupt.
Actually, I use usart1 to receive data from my PC via terminal. But I didn't receive any data.
Could u show me the problem in my program.
P/s: I use led 7 segments to view received data from PC and led_nunmber[] is an array to save data for displaying in led 7 segments.
Here is my code for usart1:
void USART_Configuration(){
     RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
     RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
     
     GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);
     GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1);
          
     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  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_Init(GPIOA, &GPIO_InitStructure);
     
     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
     GPIO_Init(GPIOA, &GPIO_InitStructure);
     
     USART1_InitStructure.USART_BaudRate = 9600;
  USART1_InitStructure.USART_WordLength = USART_WordLength_8b;
  USART1_InitStructure.USART_StopBits = USART_StopBits_1;
  USART1_InitStructure.USART_Parity = USART_Parity_No;
  USART1_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART1_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
     USART_Init(USART1, &USART1_InitStructure);
     
     USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
     //USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
     
     // Enable UART1
     USART_Cmd(USART1, ENABLE);     
     
}
void USART1_IRQHandler(void)
{
     uint8_t i = 0;
     if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
     {
          RxBuffer1[RxIndex1++] = USART_ReceiveData(USART1);
          if(RxIndex1 == 4)
          {
                USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);
          }

          for (i = 0; i<= RxIndex1; i++){
               led_number[i] = RxBuffer1[i];
          }     

     }
     if (RxIndex1 >= 4)
     {
          RxIndex1 = 0;
     }

}

Outcomes