cancel
Showing results for 
Search instead for 
Did you mean: 

Do I have to add the delay function for receiving the USART data for safely?

Carter Lee
Associate III
Posted on September 18, 2017 at 16:39

Hi.

Now I'm struggling with receiving data by USART.

Currently, I have one USART receive interrupt. and once if there is interrupted by RX, then the data saved into the queue.

I guess but I'm not sure, but while() is too fast. So I can't get the data what I want.

for example, If PC's USART terminal  send data with 0x11 0x22 0x33 0x44.. to eval kit. then procedure with delay()  in while() is working as well.

But If I remove that delay() then, I can't get data of all (0x11~0x44).

Do I have to add the delay function for receiving the USART data for safely?

What is the fairly common way to process UART frame packet?  

One more thing.

USART3_IRQHandler just one activated never after.

void USART3_IRQHandler(void) //RX

{

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

{

char rx = USART_ReceiveData(USART3); /*GetCharUSART1();*/

Uart3_EnQueue(rx);

USART_ClearITPendingBit(USART3, USART_IT_RXNE);

}

}

Did I someting miss?

12 REPLIES 12
Posted on September 19, 2017 at 15:59

I've already tried to find some example. But I can't find it. and there is no answer what if I am doing correctly, I don't need delay().

LMI2
Lead
Posted on September 19, 2017 at 19:46

Here is an old program from me. It is not exactly what you want but at least it works.

https://community.st.com/0D50X00009XkfiRSAR

Posted on September 20, 2017 at 00:31

Well it is going to take milliseconds for the data to transit, if you expect it to appear instantaneously you will be disappointed. The code will need to iterate to catch and display data.

Not everything comes with examples, some things require a conceptual understanding of the CPU and peripherals, and this doesn't need to be STM32 specific.

The STM32 USART have a single holding buffer for each of the receive and transmit paths, data gets serialized, and each byte received will get a discrete interrupt some micro-second or milli-second separated depending on baud rate. A processor running at MHz is going to iterate potentially thousands of times.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..