Skip to main content
Associate III
June 28, 2024
Question

STM32 UART Receive Problem

  • June 28, 2024
  • 12 replies
  • 5669 views

Hi, I am using STM 32 STLINK-V3. Thereis a problem with following UART receiver function. 

 

	__HAL_UART_CLEAR_FLAG(&huart5, UART_CLEAR_NEF|UART_CLEAR_OREF);
	HAL_UART_Receive(&huart5, rx_buffer, ROVER_MSG_LEN, 1000);




	 __HAL_UART_DISABLE_IT(&huart5,UART_IT_RXNE);

 

. Without clearing the flag rx_buffer remains empty even though there is a data observed from hardware with oscilloscope. I stept into the function and see flag remains up constantly but now only varying few initial bits of the buffer gets the data still rest remians empty. Is this a bug does any one knows ? 

This topic has been closed for replies.

12 replies

Andrew Neil
Super User
June 28, 2024

Please give details of your hardware setup:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

 


@Kuttay wrote:

there is a data observed from hardware with oscilloscope. 


Show on your schematic where you observe that

There's been a lot of "UART can't receive" threads lately; eg,

https://community.st.com/t5/stm32-mcus-boards-and-hardware/i-cannot-receive-data-while-using-usb-to-uart-for-nucleo-f411re/m-p/690154

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
KuttayAuthor
Associate III
June 28, 2024

PSure, I am using two gnss which are ZED-FP9P-04B-01. They are connected to STM32H735IGKx and uart5 is used. I am attaching the pin diagram.  This is how I tried to take the data as rx_buffer.

static void tcpsend_thread (void *arg)
{

	MX_UART5_Init();
	while (1)
		{
		 TickType_t xLastWakeTime = xTaskGetTickCount();
		//rx_buffer[1]=1;
		//tcpsend(rx_buffer[1]);
		osDelay(1000); //2000 or 5000

		// Enter task section
		 //__disable_irq();

	 // UART reception
	//	__HAL_UART_ENABLE_IT(&huart5,UART_IT_RXNE); // Exit critical task section
//		__HAL_UART_CLEAR_IT(&huart5, UART_CLEAR_NEF|UART_CLEAR_OREF);
//		HAL_UARTEx_ReceiveToIdle_IT(&huart5, rx_buffer, ROVER_MSG_LEN);
		__HAL_UART_CLEAR_FLAG(&huart5, UART_CLEAR_NEF|UART_CLEAR_OREF);
		HAL_UART_Receive(&huart5, rx_buffer, ROVER_MSG_LEN, 10000);
//		HAL_UART_Receive_IT(&huart5, rx_buffer, ROVER_MSG_LEN);



	 __HAL_UART_DISABLE_IT(&huart5,UART_IT_RXNE);


		//ulTaskNotifyTake(pdTRUE , portMAX_DELAY);

			if (g_rxSize <= 0)
				continue;
			//__HAL_UART_ENABLE_IT(&huart5,UART_IT_RXNE); // Exit critical task section

			int i;
			int j;
			volatile int len_gpgga=0;
			volatile int len_gpgst=0;
			for(int x=1;x<ROVER_MSG_LEN; x++){
				if(rx_buffer[x]==0x24){
					len_gpgga=x;

					for(int y=len_gpgga; y<ROVER_MSG_LEN;y++){
						if(rx_buffer[y]==0xB5){
							len_gpgst=y- len_gpgga;

							break;
						}
					}
					break;
				}

			}


			for(i=0; i<ROVER_MSG_LEN; i++){

				if (rx_buffer[i] == 0x24 && rx_buffer[i+1] == 0x47){
								 if (rx_buffer[i+3] == 0x47 && rx_buffer[i+4]== 0x47 ){
									 if(rx_buffer[i+5]== 0x41){

												memcpy(&gpgga, &rx_buffer[i], len_gpgga);
												gpgga[2]= 'P';


									 }
								 }
				}
				if (rx_buffer[i] == 0x24 && rx_buffer[i+1] == 0x47){
											 if (rx_buffer[i+3] == 0x47 && rx_buffer[i+4]== 0x53 ){
												 if(rx_buffer[i+5]== 0x54){
															 // Packet is valid, copy the data
															memcpy(&gpgst, &rx_buffer[i], len_gpgst);
															gpgst[2]= 'P';


												 }
											 }
							}
				if(rx_buffer[i] == 0xB5){

					if(rx_buffer[i+1] == 0x62){

						if(rx_buffer[i+2] == 0x01){

							if(rx_buffer[i+3] == 0x3c){

								if (rx_buffer[i+4] == 64){

									uint8_t calculatedCK_A = 0;
									uint8_t calculatedCK_B = 0;

								for (j = i+2; j < i+72 - 2; j++)
									{
										calculatedCK_A += rx_buffer[j];
										calculatedCK_B += calculatedCK_A;
									}

									if (calculatedCK_A == rx_buffer[i+72 - 2] && calculatedCK_B == rx_buffer[i+72 -1])
									{
										memcpy(&zedf9pData, &rx_buffer[i+6], sizeof(ZEDF9P_Data));


										uint8_t message[100];

										sprintf(message,"$GPHDT,%lu,T",zedf9pData.relPosHeading);
										int crc = nmea_checksum(message);
										sprintf(message+strlen(message),"*%X\r\n",crc);
										 sys_arch_sem_wait(&tcpsem, 500);
										 memset(rx_buffer, 0, sizeof(rx_buffer));



										 for (int e = 0; e<len_gpgst;e++){
											 merged[e] = gpgst[e];
										 }
										 for (int e = 0; e<300;e++){
											 merged[e+len_gpgst] = message[e];
										 }


										if (gpgga[3]=='G'){
											tcpsend(gpgga);
											osDelay(200);
											if (merged[3]=='G'){
												tcpsend(merged);
												osDelay(200);
											}

										}



										memset(gpgga, 0, sizeof(gpgga));
										memset(gpgst, 0, sizeof(gpgst));
										memset(message, 0, sizeof(message));

										break;

									}
								}
							}
						}
					}
				}
			}

	vTaskDelayUntil(&xLastWakeTime, 1000);


}

}
Andrew Neil
Super User
June 28, 2024

Please show a schematic - #3 in the guidelines:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

 


@Kuttay wrote:

I am using two gnss which are ZED-FP9P-04B-01. They are connected to STM32H735IGKx and uart5 is used.  


So how do you connect two GNSS units to one UART ?
The pin list doesn't show this (even if it were legible) - that's why you need to give a schematic.

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.