cancel
Showing results for 
Search instead for 
Did you mean: 

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

cjaya.1
Associate II
 
7 REPLIES 7
Karl Yamashita
Lead II

Post your code.

If you find my answers useful, click the accept button so that way others can see the solution.

>>Any idea about this

You're doing something wrong, debug it..

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
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

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
Up vote any posts that you find helpful, it shows what's working..
Karl Yamashita
Lead II

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 you find my answers useful, click the accept button so that way others can see the solution.

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
Lead II

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 you find my answers useful, click the accept button so that way others can see the solution.