Skip to main content
Carter Lee
Associate III
September 18, 2017
Question

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

  • September 18, 2017
  • 3 replies
  • 1596 views
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?

    This topic has been closed for replies.

    3 replies

    nibbly78
    Associate III
    September 18, 2017
    Posted on September 18, 2017 at 16:45

    post up your while loop

    generally, ring buffer would be the way to go > 

    http://www.embedded.com/electronics-blogs/embedded-round-table/4419407/The-ring-buffer

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

    I've update the main file.

    Tesla DeLorean
    Guru
    September 18, 2017
    Posted on September 18, 2017 at 16:51

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

    NO

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

    One byte at a time?

    USART_ClearITPendingBit(USART3, USART_IT_RXNE); // this is unnecessary, reading the DR clears the status

    Also you shouldn't clear the interrupt as the last thing prior to exit, there is a race hazard that will cause spurious re-entry.

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    Carter Lee
    Associate III
    September 18, 2017
    Posted on September 18, 2017 at 16:58

    Could you please let me know what am I supposed to do with the attached code to prevent hazard race problem?

    Tesla DeLorean
    Guru
    September 18, 2017
    Posted on September 18, 2017 at 17:10

    I don't have the time/resources to work on your project.

    You should perhaps review the use of volatile variables, and the size of data sscanf() writes into variables.

    If it is too overwhelming, then reduce the complexity, but you shouldn't need to insert delays for things to work properly.

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    LMI2
    Senior III
    September 19, 2017
    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