2014-05-29 03:54 AM
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
2014-05-29 07:02 AM
<< 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 Peacock2014-05-29 09:17 AM
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.2014-05-29 09:52 AM
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
2014-05-29 10:05 AM
To follow up from Jan's comment
USART_IT_XXX requires USART_GetITStatus() As they define/test a different sub-set of bits.2014-05-29 12:41 PM
<< 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 Peacock2014-05-30 03:56 AM
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 :)