I have a problem with HAL_UART_Transmit() function. I have a endless loop until switch press to stop it HAL_UART_Transmit data. But after 3500 cycles HAL_UART_Transmit() stops transmitting. Any idea about this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-02-25 10:42 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-02-26 1:58 PM
Post your code.
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
‎2023-02-26 2:25 PM
>>Any idea about this
You're doing something wrong, debug it..
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-02-26 3:39 PM
void TempReading()
{
int incr = 0;
char *p,c;
int length = 0;
uint8_t buffer[20] = {0};
while(halfull != 1)
{
char *tx = "Read\n";
HAL_UART_Transmit_IT(&huart2, (uint8_t*)tx, strlen(tx));
HAL_Delay(500);
HAL_UART_Receive_IT(&huart2, RxBuffer, 1);
HAL_Delay(500);
for(char *str =strtok((char*)RX, "\n\n"); str; str = strtok(NULL, "\n\n"))
{
p = calloc((length+2), sizeof(char));
strncpy(p, str, strlen(str)+2);
strcat(p,"\n");
if(strncmp((char*)p, "TEMP", 4) == 0)
{
strcpy(Temp[incr], p);
incr++;
break;
}
}
for(int i = 0; i<incr; i++)
{
HAL_UART_Transmit(&huart1, Temp[i], strlen(Temp[i]),HAL_MAX_DELAY);
}
memset((void*)RX, 0, 380);
memset(Data[0], '\0', 30);
incr = 0;
}
HAL_UART_Receive_DMA(&huart1, buffer, 20);
if(halfull)
{
halfull = 0;
HAL_UART_DMAStop(&huart1);
c = strtok((char*)buffer, "\r\n\n");
if(strncmp((char*)c, "stop()",5 ) == 0)
{
Stop();
break;
}
}
}
}
I did debug it, I can see data receiving but its not transmitting via huart1 as a poll method after 3500 cycle. Any idea about this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-02-26 4:39 PM
You free() any of the memory you allocate?
Is the buffer big enough for what you copy into it?
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-02-26 7:48 PM
I can see your transmit "Read\n". Then you are receiving on interrupt saving to RxBuffer but your strtok is looking at RX. You didn't post all your relevant code especially HAL_UART_RxCpltCallback so we don't know what you're doing there.
Your parenthesis don't match up so I don't know if HAL_UART_Receive_DMA and if(halfull) is inside the while(1) loop or outside of it?
Are you trying to read some string (TEMP + arguments?) from the other device on huart2 and then sending the same string to huart1? What was your intention of looking for "stop() from huart1?
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
‎2023-02-27 12:05 AM
HAL_UART_Receive_DMA and haldull is inside the while(1) loop. I am trying to read some string (TEMP + arguments) from the huart2 and then sending that data to huart1. huart1 is connected to API to display that data on screen. My intention is to stop that data when I send the command "stop()". So it will come out from that While (1) loop.
I left it running to see whether it will stop or run continuously. But after 3500 cycles it stops transmitting to the API. When I debug I can see the data is receiving from huart2.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-02-27 3:00 AM
You're still not showing what is happening in HAL_UART_RxCpltCallback. You have to be doing something with RxBuffer, maybe copying that to RX buffer? If you don't show all your relevant code and variable declaration then it's hard to know what is happening outside of TempReading()
TimerCallback tutorial! | UART and DMA Idle tutorial!
If you find my solution useful, please click the Accept as Solution so others see the solution.
