cancel
Showing results for 
Search instead for 
Did you mean: 

USART RX interrupt receive data, while there is nothing.

jean_prieur
Associate III
Posted on May 29, 2014 at 12:54

Hello everybody.

I have a problem whith USART. I send data to my STM32F4 through USART3, everything works fine. But when I stop to send datas, the USART RX interrupt still receive the last char sent each time I use the USART TX. Hope I'm clear 🙂 This is my USART interrupt code:

void
USART3_IRQHandler(
void
)
{
static
uint8_t data;
// check if the USART3 receive interrupt flag was set
if
(USART_GetFlagStatus(USART3, USART_IT_RXNE) != RESET)
{
 // Process the new received data

 usart_byte_to_MIDI_message(USART_ReceiveData(USART3));
}
// check if the USART3 is ready to send something
if
(USART_GetITStatus(USART3, USART_IT_TXE) != RESET)
{
// if there is a MIDI message to send (in the fifo buffer)
if
(fifo_bufferOut(&Midi_Out_Fifo, &data) == SUCCESS) USART_SendData(USART3, data);
// if the fifo buffer is empty, DISABLE Transmit Data interrupt
else
USART_ITConfig(USART3, USART_IT_TXE, DISABLE);
}
}

I think this is because when I send datas with USART3 TX,USART3_IRQHandler() appends and the condition
if
(USART_GetFlagStatus(USART3, USART_IT_RXNE) != RESET)
is true. Why USART_IT_RXNE is not RESET if there nothing in USART RX ? Thanks a lot ! Jean
6 REPLIES 6
jpeacock2399
Associate II
Posted on May 29, 2014 at 16:02

<< But when I stop to send datas, the USART RX interrupt still receive the last char sent each time I use the USART TX.  >>

Are you sure the data you send out isn't being echoed back by the external device?

  Jack Peacock
jean_prieur
Associate III
Posted on May 29, 2014 at 18:17

Yes i'm 100% sure of it.

The fact is, when I send data (it can be any data) with USART TX, I always receive the same data with USART RX.

So I not receive the same data that I sent, it's not an echo.

Posted on May 29, 2014 at 18:52

if
(USART_GetFlagStatus(USART3, USART_IT_RXNE) != RESET)
if
(USART_GetITStatus(USART3, USART_IT_TXE) != RESET)

I guess you meant to use the same function in both cases - I don't know which one, I don't ''speak'' ''library-sh'' - the one which reads the flags from USART_SR. JW
Posted on May 29, 2014 at 19:05

To follow up from Jan's comment

USART_IT_XXX requires USART_GetITStatus()

As they define/test a different sub-set of bits.

Tips, Buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
jpeacock2399
Associate II
Posted on May 29, 2014 at 21:41

<< Yes i'm 100% sure of it. >>

Does that mean you looked at the incoming RxD line with a scope to make sure nothing was being received from the remote device while you were sending?

  Jack Peacock

jean_prieur
Associate III
Posted on May 30, 2014 at 12:56

Ok thanks everybody, I added

if
(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)

and now it's working fine ! @Community member, yes my first try was to test the line with a scope 🙂