cancel
Showing results for 
Search instead for 
Did you mean: 

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

fredy368
Associate II
Posted on September 14, 2011 at 17:31

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.

#stm32-usart

1 REPLY 1
fredy368
Associate II
Posted on September 21, 2011 at 04:41

I found the problem which causes the RxCounter to count automatically.

If you add the RxBuffer to watch in IAR, the RxCounter will start to count even the routine has not been called.