Skip to main content
cjaya.1
Associate III
February 26, 2023
Question

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

..

This topic has been closed for replies.

7 replies

Karl Yamashita
Principal
February 26, 2023

Post your code.

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
cjaya.1
cjaya.1Author
Associate III
February 26, 2023
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

Tesla DeLorean
Guru
February 27, 2023

You free() any of the memory you allocate?

Is the buffer big enough for what you copy into it?

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Tesla DeLorean
Guru
February 26, 2023

>>Any idea about this

You're doing something wrong, debug it..

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Karl Yamashita
Principal
February 27, 2023

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?

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
cjaya.1
cjaya.1Author
Associate III
February 27, 2023

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.

Karl Yamashita
Principal
February 27, 2023

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

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source