AnsweredAssumed Answered

help! Anyone knows why the RxCounter gets a non-stop counting

Question asked by yu.fredy on Sep 14, 2011
Latest reply on Sep 21, 2011 by yu.fredy
Hi, does anyone knows why the RxCounter in the interrupt routine always up-counting even the STM32 does not get into interrupt? I am trying some example codes about the USART. All the settings are the as usual, but when I run it in debug mode in IAR, I saw that the RxCounter started to count even I had not pressed run to start the program. Below are the codes in the interrupt routine. Anyone has any idea about that?

NbrOfDataToRead = 0x20;

void USART1_IRQHandler(void)
{
 if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
 {
    /* Read one byte from the receive data register */
    RxBuffer[RxCounter++] = (USART_ReceiveData(USART1) & 0x7F);
       
         if(RxCounter == NbrOfDataToRead)
    {
      /* Disable the USART Receive interrupt */
      USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);
    }
 }

 if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET)
 {  
    /* Write one byte to the transmit data register */
      USART_SendData(USART1, TxBuffer[TxCounter++]);
    if(TxCounter == NbrOfDataToTransfer)
    {
      /* Disable the USART1 Transmit interrupt */
      USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
    }
 }
}

If I just put a variable++; alone in the routine, the crazy counting of that variable won't be happened. The crazy counting of the RxCounter is very strange, it won't stop even I stopped the program to execute that line.

Outcomes