cancel
Showing results for 
Search instead for 
Did you mean: 

STM32f205 manual half-duplex on UART

Posted on September 01, 2015 at 12:26

Hello!

I use a interrupt controlled uart communication which sends and receives its data over a powerline circuit. Both sending and receiving work fine but due to the circuit all the data which is send on TX will be received at the same time on RX. To prevent receiving my own data all the time I'd like to disable the receiving interrupt during transmission. I tried to do this via the following function:

void
PL_SendData(uint16_t data)
{
USART_ITConfig( USART6, USART_IT_RXNE, DISABLE ); 
//disable the receiving interrupt
USART_SendData(USART6, data); 
//actually send the data
USART_ITConfig( USART6, USART_IT_RXNE, ENABLE ); 
//enable the receiving interrupt
}

Inside the interrupt I simply send all received data over a different uart connection.

void
USART6_IRQHandler (
void
) {
if
(USART_GetFlagStatus (USART6, USART_FLAG_RXNE) == SET)
{
GPIO_Toggle_LED(1);
//send all data to another UART
USART_SendData (USART2, USART_ReceiveData (USART6));
}
}

My expected behavior would be that I only see data on USART2 which comes from the communication partner of USART6 but NOT the data USART6 is sending itself. Unfortunately I still receive every message on USART2 which is transfered by USART6. Did I disable the interrupt correctly or did I miss something else? I'd be glad about some advice! Thanks in advance
2 REPLIES 2
Posted on September 01, 2015 at 18:41

Won't SendData return immediately? You'd have to wait on TC to know the last bit hit the wire.

As I recall you can also enable/disable receive/transmit halves of the USART independently.

Note that disabling the interrupt won't stop the USART from receiving data, or getting over-run errors, which must be cleared, if you don't service the USART properly.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on September 02, 2015 at 09:07

Thanks for your reply clive1! I did modify the send routine to only disable the receive interrupt during sending and cleared the RX flag preliminary to re-enabling the interrupt.

void
PL_SendData(uint16_t data)
{
USART_ITConfig( USART6, USART_IT_RXNE, DISABLE ); 
//disable only RX interrupt
USART_ClearFlag(USART6,USART_FLAG_RXNE); 
//and every pending calls
USART_SendData(USART6, data);
while
(USART_GetFlagStatus(USART6, USART_FLAG_TC) == RESET); 
//until transmission complete
USART_ClearFlag(USART6,USART_FLAG_RXNE); 
//clear receive flag
USART_ITConfig( USART6, USART_IT_RXNE, ENABLE ); 
//enable interrupt again
}

The behavior does get a little closer to my purpose. Now only the last transmitted data block will be received. So if I transfer more than one data blocks in a row (eg 1234 via uart terminal), only the last one (4) will be received again. I tried reading the receive buffer one more time previous to re-enabling the interrupt as well but it didn't change the outcome. Any further advice?