Uart Receive IT not receiving complete string
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-06-06 11:08 PM - last edited on ‎2024-06-07 1:54 AM by Amel NASRI
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.
- Labels:
-
STM32L0 Series
-
UART-USART
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-06-06 11:38 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-06-07 1:11 PM
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?
TimerCallback tutorial! | UART and DMA Idle tutorial!
If you find my solution useful, please click the Accept as Solution so others see the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-06-07 1:23 PM
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);
Up vote any posts that you find helpful, it shows what's working..
