AnsweredAssumed Answered

USART2 interrupt continuosly fires

Question asked by stokic.srdjan on Mar 11, 2015
Latest reply on Mar 11, 2015 by Clive One
Hello all,

I have a problem with my USART2 interrupt on STM32L151.

I have the USART_IT_RXNE, and USART_IT_TXE interrupts enabled on UART2. All other interrupts are disabled. 

The interrupt works fine until something weird occurs. It starts to trigger continuously and none of the two checks for RXNE, and TXE get processed. It seems that the reson for triggering of the interrupt is unknown. I also checked the UART registers and nothing weird is happening in there. 

Here is the code of my interrupt handler:
uint32_t rx_in = 0;
uint32_t tx_in = 0;
uint32_t int_in = 0;
uint32_t unknown_in = 0;
uint32_t cts_in = 0;


/**
  * @brief  This function handles USART2 global interrupt request.
  * @param  None
  * @retval None
  */
void USART2_IRQHandler( void )
{


     int_in++;
     if ( USART_GetITStatus( USART2, USART_IT_RXNE ) != RESET ) {
          rx_in++;
          /* Read one byte from the receive data register */
          unsigned char temp_buf[1];
          temp_buf[0] = USART_ReceiveData( USART2 ) & 0x7F;
          ser_push( temp_buf, 1 );
     }


     else if ( USART_GetITStatus( USART2, USART_IT_TXE ) != RESET ) {
          tx_in++;
          if ( USB_tx_reader != USB_tx_writer ) {
               char ch;
               ch = USB_TX_Buffer[USB_tx_reader];
               /* Write one byte to the transmit data register */
               USART_SendData( USART2, ch );


               USB_tx_reader = ( USB_tx_reader + 1 ) % USB_OUTPUT_BUFFER_SIZE;
          } else {
               /* Disable the EVAL_COMX Transmit interrupt */
               USART_ITConfig( USART2, USART_IT_TXE, DISABLE );
          }
     }


     else if ( USART_GetITStatus( USART2, USART_IT_CTS ) != RESET ) {
          cts_in++;
     }


     else {
          unknown_in++;
     }
}

I have counters in the code which I check periodically. 
Ideally the int_in variable should be equal to rx_in+tx_in, but then I suddenly see unknown_in gets to 150.000 quickly and then I get stack overlow and various crashes.

Any ideas?

Outcomes