Skip to main content
Visitor II
June 7, 2024
Question

Uart Receive IT not receiving complete string

  • June 7, 2024
  • 3 replies
  • 1349 views

Hi,

We are using STM32L010C6 Microcontroller, we need to recive the a fixed size of strings (10 charecters ) using interrupted method. But we are not able to receive the charecters completely and its get stuck on the cpltcallback function also. What could be the issue and please gibe me some auggestion to resolve this issue. Iam attaching the main file for the referanc.

    This topic has been closed for replies.

    3 replies

    Super User
    June 7, 2024

    Hi,

    what happens, if there is a spike on the line and receiver sets "error" ? (never cpltcallback ...)

    So just how i do: "packet" gets a delimiter (= end of string), receiver is on INT for 1 byte , and also receiver error callback (no better idea...) throw away and set INT for 1 byte again.

    So i get the string (of any length (needs buffer of > size and limit , to reset string to zero, if "too long") always, even if there was an error .

    Try it this way.

    Graduate II
    June 7, 2024

    But we are not able to receive the charecters completely and its get stuck on the cpltcallback function also. 

    So what string are you expecting and what does the data buffer show? 

    If you mean you're stuck in HAL_UART_RxCpltCallback, how do you know you're getting stuck? Are you debugging and the cursor stays where?

    Graduate II
    June 7, 2024

    The function completes immediately, there isn't going to be anything in the buffer.

    To use string functions there needs to be a terminal NUL, so 10 characters AND a NUL

    Flags set in interrupt/callback context need to be volatile

     memset(s,0,10);
     printf("haiii\r\n");
     HAL_UART_Receive_IT(&husart2, (unsigned char *)s, 10); // << COMPLETES IMMEDIATELY
     printf("%s\r\n",s);