2015-03-11 06:55 AM
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 #interrupt2015-03-11 07:03 AM
Use USART_ClearITPendingBit to clear bit.
2015-03-11 07:27 AM
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 JW2015-03-11 07:53 AM
Hi Jan,
I just checked, when the interrupt occurs, ORE bit is 0, so its not that. :(2015-03-11 08:01 AM
Do you have a debugger view parked over the USART peripheral?
2015-03-11 08:03 AM
Hi Clive,
Could you please explain in more detail? I''m not sure I understand your question2015-03-11 08:04 AM
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 semicolons2015-03-11 08:06 AM
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.2015-03-11 08:12 AM
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...2015-03-11 08:35 AM
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.