cancel
Showing results for 
Search instead for 
Did you mean: 

USART2 interrupt continuosly fires

srdjan
Associate II
Posted on March 11, 2015 at 14:55

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?

#stm32l151 #uart #interrupt
11 REPLIES 11
tm3341
Associate II
Posted on March 11, 2015 at 15:03

Use USART_ClearITPendingBit to clear bit.

Posted on March 11, 2015 at 15:27

You have an overflow error.

From the RM:

RXNEIE: RXNE interrupt enable

1: An USART interrupt is generated whenever ORE=1 or RXNE=1 in the USART_SR

register

JW
srdjan
Associate II
Posted on March 11, 2015 at 15:53

Hi Jan,

I just checked, when the interrupt occurs, ORE bit is 0, so its not that. :(

Posted on March 11, 2015 at 16:01

Do you have a debugger view parked over the USART peripheral?

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
srdjan
Associate II
Posted on March 11, 2015 at 16:03

Hi Clive,

Could you please explain in more detail? I''m not sure I understand your question

Posted on March 11, 2015 at 16:04

Have the unknown branch record the status to a table. Review the table once you see 100

Make sure TXE is actually disabled if you have no data, and that the braces (if/then/else) are being interpreted by the compiler as expected. Looks ok as I scan it, but watch for missing/needed semicolons
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on March 11, 2015 at 16:06

Could you please explain in more detail? I''m not sure I understand your question

What debugger/tool chain are you using? Do you have a window view of the USART open showing you the internal register content? If yes, be aware that doing that is invasive, altering the behaviour of the peripheral.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
srdjan
Associate II
Posted on March 11, 2015 at 16:12

I'm using IAR EWARM.. and you are right I'm having the register window open with the USART2->SR register content..

Ahh.. I'll dump the register content somewhere else for examining...

srdjan
Associate II
Posted on March 11, 2015 at 16:35

Thank you for your help.

The problem was indeed an overrun in the receiver. 

The bluetooth module I'm trying to communicate with is ignoring my RTS signal, and is sending me data too fast, thus overflowing my input buffer. This is a separate problem from what I was experiencing with the interrupt, but now that I have this issue resolved I can proceed with work.