This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C129ENCPDT: While loop hangs in TCP communication

Part Number: TM4C129ENCPDT


Hi,

I am working on TM4C129ENCPDET as the main controller. I want to send data from the peripheral module using TCP/IP data transfer. Peripheral module interfaced with the controller via UART communication. I am using a while loop for waiting data from this peripheral module. But code tuck on this loop and no data transfer. I am using the TCP echo server code as a reference. Please support.

Regards

GPM

  • I am confused on what you are asking. Are you able to get the enet_tcpecho_server example to work?  Is the problem getting information from your external device by UART? Please provide more specific details.

  • Hi,

    enet_tcpecho server working perfectly. I need to fetch data from an external device via UART send that data via TCP/IP communication. The procedure is as follows

    1. Receiving command from the slave device via TCP to read external device

    2 Processing command

    3. Sending read request to the external device via UART

    4. waiting for data using while loop

    5. Receiving data via UART

    6. Send external device data via TCP to slave.

    Regards

    GPM

  • Have you verified with a scope or logic analyzer that data is coming out of the Tiva Uart? Is it the correct baud rate? Have you verified that data is coming back from the external device using a scope or logic analyzer? If the answer to all of these questions is yes, then please attach the section of code where you are polling the UART.

  • Hi bob,

    Yes, the External UART device working perfectly independently. withuout while loop it also works but no data loaded to TCP transmit buffer. but when we using while it stuck on that loop. code is as follows

    //*****************************************************************************
    //
    // Callback function to process the received data from the client.
    //
    //*****************************************************************************
    static err_t
    echo_recv( void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
    {
    	uint32_t ui32index;
    	uint32_t ui32len;
    	char *pcpayLoad;
    	char pcheaderMsg[45];
    	char buf[BUFRSIZE];
    	uint32_t ui32statuslen;
    	int i;
    	uint32_t Chk_Sum=0;
    	extern int temp_count,in,x10,x11,y10,y11,z10,z11,x20,x21,y20,y21,z20,z21,x30,x31,y30,y31,z30,z31,x40,x41,y40,y41,z40,z41;
    
    	//
    	// Clear the Idle time counter.
    	//
    	g_ui32tcpPollTick = 0;
    
    	if (err == ERR_OK && p != NULL)
    	{
    		//
    		// tcp_recved must be called when the application has processed the
    		// data and is prepared to receive more.
    		//
    		tcp_recved(pcb, p->tot_len);
    
    		//
    		// Obtain the payload length and the pointer to the payload.
    		//
    		pcpayLoad = (char *)p->payload;
    		ui32len = p->tot_len;
    
    		for(ui32index = 0;ui32index <ui32len;ui32index++)
    		{
    			g_rxtcpBuffer[ui32index] =pcpayLoad[ui32index];
    		}
    		for(ui32index = 0;ui32index <ui32len;ui32index++)
    		{
    
    			// UARTprintf("\rReceived bytes :%x", g_rxtcpBuffer[ui32index]);
    			//sprintf(buf,"Received bytes <%x>\n",g_pctcpBuffer[ui32index]);
    			buf[ui32index]=g_rxtcpBuffer[ui32index];
    			// sprintf(buf,"Received bytes <%x>\n",g_rxtcpBuffer[ui32index]);
    			// UARTSend((uint8_t *)buf,strlen(buf),UART5_BASE);
    		}
    
    		if(buf[0] == START_OF_Rx)
    		{
    			switch(buf[1])
    			{
    
    				case MODE_CMD_SH:
    				{
    					switch(buf[2])
    					{
    
    						case SH_PARA_CMD:
    						{
    							g_SHtxBuffer[0] =START_OF_Tx;
    							g_SHtxBuffer[1] =SH_PARA;
    							g_SHtxBuffer[2] =END_OF_Tx;
    							g_SHtxBuffer[3] =0x26;
    							UARTSend((uint8_t *)g_SHtxBuffer,4,UART4_BASE // command to external UART device
    							while(g_UART4Flag);// waiting for data from UART device
    
    							g_pctcpBuffer[0]=START_OF_Tx;
    
    							for (i=1;i<9;i++)
    							{
    								g_pctcpBuffer[i]=g_UART4Buffer[i];
    							}
    							for (i=1;i<9;i++)
    							{
    								Chk_Sum=(Chk_Sum)^(g_pctcpBuffer[i]);
    							}
    							g_pctcpBuffer[9] = Chk_Sum;
    
    							g_pctcpBuffer[10]=END_OF_Tx;
    							tcp_write(pcb, g_pctcpBuffer, 11, 0);
    
    							break;
    						}
    					}
    				}
    
    			}
    		}
    
    
    		//
    		// Dereference a pbuf chain.
    		//
    		pbuf_free(p);
    
    		//
    		// Call tcp_sndbuf() to find the maximum amount of data that can be
    		// sent.
    		//
    		if(ui32len > tcp_sndbuf(pcb))
    			ui32len = tcp_sndbuf(pcb);
    
    		//
    		// Enqueues the data stored in g_pctcpBuffer. The length of the data
    		// is passed in ui32len. The argument copy may be either 0 or 1 and
    		// indicates whether the new memory should be allocated for the data to
    		// be copied into. If the argument is 0, no new memory should be
    		// allocated and the data should only be referenced by pointer.
    		//
    
    		// tcp_write(pcb, g_pctcpBuffer, ui32len+ui32statuslen, 0); //tcp_output()
    		// tcp_write(pcb, g_pctcpBuffer, 27, 0); //tcp_output()
    
    		//
    		// Specifies the callback function echo_sent be called when data has
    		// successfully been received (i.e. acknowledged) by the remote host.
    		// The len argument passed to the sent callback function gives the
    		// number of bytes that were acknowledged by the last acknowledgment.
    		//
    		tcp_sent(pcb, echo_sent);
    	}
    	else
    	{
    		//
    		// If there is an error during pbuf allocation then free the pbuf.
    		//
    		pbuf_free(p);
    	}
    
    	//
    	// If the remote host requests a connection close with p == NULL then
    	// close the connection held by the PCB.
    	//
    	if(err == ERR_OK && p == NULL)
    	{
    		close_conn(pcb);
    	}
    
    	return ERR_OK;
    }
    
    //*****************************************************************************
    / UART Function
    //
    //*****************************************************************************
    void UART4IntHandler(void)
    {
    	uint32_t ui32Status4;
    
    	//
    	// Get the interrrupt status.
    
    	ui32Status4 = ROM_UARTIntStatus(UART4_BASE, true);
    
    	//
    	// Clear the asserted interrupts.
    	//
    	ROM_UARTIntClear(UART4_BASE, ui32Status4);
    
    	//
    	// Loop while there are characters in the receive FIFO.
    	//
    	while(ROM_UARTCharsAvail(UART4_BASE))
    	{
    
    		// * Receive Data Available */Neetz
    		g_UART4Buffer[g_UART4Count] = ROM_UARTCharGetNonBlocking(UART4_BASE);
    
    		if(g_UART4Buffer[g_UART4Count]==('&'))
    		{
    			g_UART4Flag=1;
    			g_UART4Count=0;
    		}
    		else
    		{
    			g_UART4Count++;
    			if ( g_UART4Count == BUFRSIZE )
    			{
    				/* buffer overflow */
    				g_UART4Count=0;
    				memset (g_UART4Buffer, 0, BUFRSIZE);
    			}
    		}
    	}
    }
    
    

    regards

    GPM

  • First, I edited your last post. I copied your C code and restored the indents. Then I used the </> button to paste the code back into your post. It makes the code much more readable.

    Have you run the code with a breakpoint in the UART4IntHandler() function? Does the code ever get there? If yes, what is the value returned by the call to ROM_UARTIntStatus()? If no, then please show the code you use to enable the UART4 interrupts and a dump of the UART4 registers.

  • Hi Bob,

    UART working perfectly in normal operation,  But when we using TCP , the code does not hit in the breakpoint in the UART4IntHandler() function. 

    
    
    /******************************************************************************
    ** Function name    :           UARTInit()
    **
    ** Descriptions     :           UART Initialization
    **
    ** parameters       :           None
    **
    ** Returned value   :           None
    **
    ******************************************************************************/
    void UARTInit(void)
    {
            //
            // Enable the peripherals
            //
            ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
            ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    
            ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3);
            ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
    
            ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART4);
            ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
    
            ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART5);
            ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
            //
            // Set GPIO A0 and A1 as UART pins.
            //
            GPIOPinConfigure(GPIO_PA0_U0RX);
            GPIOPinConfigure(GPIO_PA1_U0TX);
            ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
            GPIOPinConfigure(GPIO_PJ0_U3RX);
            GPIOPinConfigure(GPIO_PJ1_U3TX);
            ROM_GPIOPinTypeUART(GPIO_PORTJ_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
            GPIOPinConfigure(GPIO_PK0_U4RX);
            GPIOPinConfigure(GPIO_PK1_U4TX);
            ROM_GPIOPinTypeUART(GPIO_PORTK_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
            GPIOPinConfigure(GPIO_PC6_U5RX);
            GPIOPinConfigure(GPIO_PC7_U5TX);
            ROM_GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_6 | GPIO_PIN_7);
    
            //
            // Configure the UART for 115,200, 8-N-1 operation.
            //
            ROM_UARTConfigSetExpClk(UART0_BASE, g_ui32SysClock, 115200,
                  (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                   UART_CONFIG_PAR_NONE));
    
            ROM_UARTConfigSetExpClk(UART3_BASE, g_ui32SysClock, 115200,
                  (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                   UART_CONFIG_PAR_NONE));
    
            ROM_UARTConfigSetExpClk(UART4_BASE, g_ui32SysClock, 115200,
                  (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                   UART_CONFIG_PAR_NONE));
    
            ROM_UARTConfigSetExpClk(UART5_BASE, g_ui32SysClock, 115200,
                  (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                   UART_CONFIG_PAR_NONE));
            //
            // Enable the UART interrupt.
            //
            ROM_IntEnable(INT_UART0);
            ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
    
            ROM_IntEnable(INT_UART3);
            ROM_UARTIntEnable(UART3_BASE, UART_INT_RX | UART_INT_RT);
    
            ROM_IntEnable(INT_UART4);
            ROM_UARTIntEnable(UART4_BASE, UART_INT_RX | UART_INT_RT);
    
            ROM_IntEnable(INT_UART5);
            ROM_UARTIntEnable(UART5_BASE, UART_INT_RX | UART_INT_RT);
    

  • Would you please put a breakpoint on the while loop, and when the CPU halts at the breakpoint, check the value of the Processor Status Register (xPSR). I want to verify that you are not in an interrupt service routine.