Skip to main content
vimmi
Associate
July 11, 2016
Question

STM32 HAL_UART Receive

  • July 11, 2016
  • 2 replies
  • 744 views
Posted on July 11, 2016 at 20:15

We are using HAL_UART_Receive function as mentioned below in the code for testing:

while(__HAL_UART_GET_FLAG(&huart1,UART_FLAG_RXNE)== RESET){};

     {

      for (uint8_t i=0; i < 5 ; i++)

      {

       HAL_UART_Receive(&huart1,RData,RdSize1,Timeout_test1);

        RxDataStr = RxData[i];

      }

     }

RData is defined as uint8_t RData[5];

When we send the data for example ''Test1''. I can see only 1st character from the data. I debugged through the code and it seems that Timeout is occurring and it is not going through the HAL_UART_Receive loop to receive the rest of the data.

Please help!
    This topic has been closed for replies.

    2 replies

    Tesla DeLorean
    Guru
    July 12, 2016
    Posted on July 12, 2016 at 02:07

    Perhaps it would be less confusing if you had some coherent naming, and provided enough code and defines for things to make sense?

    What is RxData?

    The STM32 receives one character at a time, RXNE doesn't mean 5 characters are ready.

    RData is a pointer to RData[0..4], not RData[i]

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Bryan Guo
    Associate II
    April 27, 2017
    Posted on April 27, 2017 at 06:52

    I think your code should be like this first.  Otherwise, you will only change the value of RData[0].  

    while(__HAL_UART_GET_FLAG(&huart1,UART_FLAG_RXNE)== RESET){};

         {

          for (uint8_t i=0; i < 5 ; i++)

          {

           HAL_UART_Receive(&huart1,&RData[i], RdSize1,Timeout_test1);

            RxDataStr = RxData[i];

          }

         }

    BTW, I also meet the timeout issue. If I input a character before I call  

    HAL_UART_Receive(), it will return

     timeout and it will always return timeout after that.