cancel
Showing results for 
Search instead for 
Did you mean: 

UART Transmit problem

m_a_amirian
Associate II
Posted on July 16, 2016 at 09:55

Hello!

I'm working on UART comunication between stm32f407 and PC. I want to transmit 4 character via ''senddata()'' function shown below.

USART_SendData(USART1,'D');

while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET);

USART_SendData(USART1,'A');

while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET);

USART_SendData(USART1,'T');

while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET);

USART_SendData(USART1,'A');

while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET);

 the problem is that when i wait for TC flag after each send, it won't change i mean it remains low. Therefore, the program is stuck in the while loop. how can i become sure of a transmit completion? isn't it the right way? According to the user manual file (Page 749-Fig.249), TC is not set until the last data is sent. how can i use it?

when i remove while loops the program works fine but it only sends the last character to the PC.

(usart1 is configured truly.)
2 REPLIES 2
Posted on July 16, 2016 at 13:48

The processor is running much faster.than the USART, you should front wait on TXE rather than back wait on TC.

If you have the debugger displaying USART SR it will interfere with TC and RXNE

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
pedro23
Senior
Posted on July 18, 2016 at 11:53

clive1 is telling you to do this:

    USART_SendData(USART1,c);

    while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);