AnsweredAssumed Answered

USART interrupt problem

Question asked by bien.vinh on Aug 19, 2011
Latest reply on Aug 19, 2011 by Clive One
Hi Guys, I'm working on Usart programming in IAR environment. But I got a problem. The USART interrupt handler seemed not to be called. Here's my code:

void initUART2()
{
  USART_InitTypeDef  uart2Init;
    USART_ClockInitTypeDef uart2ClockInit;
  GPIO_InitTypeDef gpioA;
  NVIC_InitTypeDef NVIC_InitStructure;
  RCC_APB1PeriphClockCmd( RCC_APB1Periph_USART2, ENABLE );     
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  ///////////SetUart2 GPIO
  gpioA.GPIO_Pin=GPIO_Pin_2;
  gpioA.GPIO_Speed=GPIO_Speed_50MHz;
  gpioA.GPIO_Mode=GPIO_Mode_AF_PP;
  GPIO_Init( GPIOA, &gpioA);
   gpioA.GPIO_Pin = GPIO_Pin_3;
   gpioA.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOA, &gpioA);     
  //////////////////////////InitUART
  uart2Init.USART_BaudRate=9600;
  uart2Init.USART_WordLength=USART_WordLength_8b;
  uart2Init.USART_StopBits=USART_StopBits_1;
  uart2Init.USART_Parity=USART_Parity_No;
  uart2Init.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;
  uart2Init.USART_HardwareFlowControl=USART_HardwareFlowControl_None;        
  USART_Init(USART2,&uart2Init);
  ////////////////////////////InitUARTClock
     uart2ClockInit.USART_Clock=0;//USART_Clock_Enable;
   uart2ClockInit.USART_CPOL=0;//USART_CPOL_Low;
   uart2ClockInit.USART_CPHA=0;//USART_CPHA_1Edge;
   uart2ClockInit.USART_LastBit=0;//USART_LastBit_Disable;
  USART_ClockInit(USART2,&uart2ClockInit); 
  
   /////////////////InterruptConfig
  

NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init( &NVIC_InitStructure );


USART_ITConfig( USART2, USART_IT_RXNE, ENABLE );
    USART_ClearFlag(USART1,USART_FLAG_TC);
    //////////////////Enable UART 
    USART_Cmd(USART2,ENABLE);
}
//////////////////////////


///////////////////////////////////
void USART2_IRQHandler(void)
{
  if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
  {
    /* Read one byte from the receive data register */
    RxBuffer2[RxCounter++] = USART_ReceiveData(USART2);         

    /* Clear the USART2 Receive interrupt */
    USART_ClearITPendingBit(USART2, USART_IT_RXNE);

    if(RxCounter == 100)
    {
      /* Disable the USART2 Receive interrupt */
      USART_ITConfig(USART2, USART_IT_RXNE, DISABLE);
    }
  }
}


Are there problems in my source code? Plz, help me! Thanks!

Outcomes