cancel
Showing results for 
Search instead for 
Did you mean: 

Uart Receive IT not receiving complete string

Dvdasc
Associate

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.

3 REPLIES 3
AScha.3
Chief III

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.

If you feel a post has answered your question, please click "Accept as Solution".
Karl Yamashita
Lead III

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?

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.

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);

 

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