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.

EK-TM4C123GXL UART data loss

Other Parts Discussed in Thread: EK-TM4C123GXL

Hi there,

I am sending data to my EK-TM4C123GXL via UART from a java application. Both applications are set up to use the same uart configuration (baudrate, bit setup). Whenever the java application sends data chunks in small timesteps, the EK-TM4C123GXL will drop some of the data to keep up with the transmission speed of the java application. 

Is this a problem with my programm or is this a hardware limitation (limited receive buffer or the likes)?

I set up my UART like this:

	FPUEnable();
	FPULazyStackingEnable();

    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);
    //
    // Enable the GPIO Peripheral used by the UART.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    //
    // Enable UART0
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    //
    // Configure GPIO Pins for UART mode.
    //
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Use the internal 16MHz oscillator as the UART clock source.
    //
    UARTConfigSetExpClk(UART0_BASE,
    		ROM_SysCtlClockGet(),
    		UART_BAUD_RATE,
            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
    SysCtlDelay(1000);

    UARTFIFOLevelSet(UART0_BASE, UART_FIFO_TX1_8, UART_FIFO_RX1_8);

And I receive my data chunks like this:

		while (UARTCharsAvail(UART0_BASE)) {
			g_uartBuffer[g_uartBufferPosition++] = UARTCharGet(UART0_BASE);
			extractPacket();
		}

I am not using interrupts, as I perform all processing work in a continuous while-loop that fetches new UART data whenever available. (fyi I was using interrupts before, but to no avail. The same problem occured beforehand).

Any help or clarification would be greatly appreciated. Thanks.

  • Hello Kurai,

    You can increase the system clock frequency as it is not very evident what is happening in the extractPacket() function call and what the timesteps are

    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                           SYSCTL_XTAL_16MHZ);

    Replace by
        SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                           SYSCTL_XTAL_16MHZ);

    Regards

    Amit

  • Hello Amit,

    I tried your suggestion, but unfortunately that did not solve my problem. For the sake of completeness, here is my extractPacket function:

    	uint8_t g_uartBuffer[sizeof(UARTPacket)];
    	volatile int g_uartBufferPosition = 0;
    
    	void extractPacket() {
    		// Extract packets from the buffer
    		if (g_uartBufferPosition >= sizeof(BasePacketHeader)) {
    			// Reference memory as entire packet. Note: packet might not actually be complete yet, so don't treat it as such.
    			// Accessing the header is fine, as we've already read at least the header.
    			UARTPacket& bufferedPacket = *(UARTPacket*)g_uartBuffer;
    			if (bufferedPacket.isValid()) {
    				int packetLength = g_uartBufferPosition - sizeof(BasePacketHeader);
    				if (packetLength >= bufferedPacket.header.payloadLength) {
    					// Command complete
    					// reset buffer position
    
    					UARTPacket* pPacket = new UARTPacket(bufferedPacket);
    					if ( pPacket ) {
    						g_pUARTController->addPacket(pPacket);
    					}
    
    					// Packet seems valid, reduce buffer position
    					g_uartBufferPosition = 0;
    				}
    			}
    			else {
    				//invalid packet, reset buffer position
    				g_uartBufferPosition = 0;
    			}
    		}
    	}

    All it does is check whether the buffer contains a complete packet and create a new packet instance if it does, which is then processed at a later point in time.

  • Hello Kurai,

    The Buffer in UART is 16 locations deep, So if the function is being called too often then it may be losing data. You may want to check the OE bit in the UART Data Register to make sure that there is no Overrun Error occurring.

    Regards

    Amit