cancel
Showing results for 
Search instead for 
Did you mean: 

Ethernet uart flow problem with clock

Kuttay
Associate II
void tcpsend (char *data)
{
	// send the data to the connected connection
	netconn_write(conn, data, strlen(data), NETCONN_COPY);
	// relaese the semaphore
	sys_sem_signal(&tcpsem);
}
//
//void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)
//{
//   // a++;
//    if(UartHandle->Instance == UART5)
//    {
//        //if (a%100==0)
//       //     HAL_UART_Transmit(&huart3, (uint8_t *)rxd, 1, 0xFFFF);
//       // HAL_UART_Receive_IT(&huart5, rx_buffer, ROVER_MSG_LEN);
//        HAL_UARTEx_ReceiveToIdle_IT(&huart5, rx_buffer, ROVER_MSG_LEN);
//    }
//}
static void tcpsend_thread (void *arg)
{

	MX_UART5_Init();
	while (1)
		{
		//rx_buffer[1]=1;
		//tcpsend(rx_buffer[1]);
		osDelay(200); //2000 or 5000

		// Enter task section
		 //__disable_irq();

	  //  UART reception
		HAL_UARTEx_ReceiveToIdle_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;

									}
								}
							}
						}
					}
				}
			}

//		HAL_UART_RxCpltCallback(&huart5);

}

}

I am trying to get continuous data flow from ethernet but when I change processor clock It does not work. Should it be dependent to processor clock or how can i make independent? I guess I am having trouble about the code flow. How should I be using receive function if that is the problem?

0 REPLIES 0