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.

Compiler/F28M36H53C2: F28M36H53C2: UART RX FIFO

Part Number: F28M36H53C2

Tool/software: TI C/C++ Compiler

Hello,

I'm facing a configuration issue with UART FIFO.

My UART is configured as fallow:

void BSL_UartInit()
{
	//Initialize the UART
	//Set the baud rate = 115200
	//Number of data bits = 8
	//Turn off parity
	//Number of stop bits = 1
	UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(SYSTEM_CLOCK_SPEED), 115200,
			(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
	//Enable trasmit and receive FIFO
	UARTFIFOEnable(UART0_BASE);
	//Registers of UART interrupt
	UARTIntRegister(UART0_BASE, UartIntHandler);
	//Enable UART interrupt
	UARTIntEnable(UART0_BASE, UART_INT_RX | /*UART_INT_RT |*/ UART_INT_BE);
	//Enable the UART
	UARTEnable(UART0_BASE);

	UartTxFSM.status = UART_TX_FSM_IDLE;
}

So I write the follow code to receive data from UART:

#define UART_RX_BUF_LENGTH (32)
#define UART_ADDRESS	(0x10)
#define END_BYTE 0x7E

struct {
	enum {
		UART_TX_FSM_IDLE,
		UART_TX_FSM_TX_BREAK,
		UART_TX_FSM_TX_DATA
	} status;
	unsigned char buf[UART_TX_FIFO_LENGTH];
	unsigned char address;
	//unsigned char len;
	unsigned int len;
} UartTxFSM;

struct {
	int idx;
	int timeout;
	int error;
	unsigned char buf[UART_RX_BUF_LENGTH];
	int len;
} UartRx;

void UartIntHandler(void)
{
	unsigned long status;
	char data;
	unsigned char ck = 0xff;
    
	//break received
	if(status & UART_INT_BE)
	{
		UARTIntClear(UART0_BASE, UART_INT_BE);
		data = UARTCharGetNonBlocking(UART0_BASE); //discard empty data
		UartRx.idx = 0;
		UartRx.timeout = 0;
		UartRx.error = 0;
	}

	//if(status & UART_INT_RT)
	//{
	//	UARTIntClear(UART0_BASE, UART_INT_RT);
	//	UartRxTimeout = 1;
	//}

	if(status & UART_INT_RX)
	{
		UARTIntClear(UART0_BASE, UART_INT_RX);
		data = UARTCharGetNonBlocking(UART0_BASE);
		if(UartRx.idx == UART_RX_BUF_LENGTH || data & 0x00000f00)
			UartRx.error = 1;
		else
		{
			UartRx.idx++;
			UartRx.buf[UartRx.idx] = data & 0x000000ff;
			ck += data;
		}
         }
}

At the end, the UartRx.buff contain only 0x7E value, that is the last value sent from the other device.

Am I missing something?

  • Hi Daniel,

    Thanks for the detailed information. This thread has been assigned to C2000 experts and should be answered shortly.

    Regards
    Chen
  • Daniel,

    what happens if you only send half of the data, does only the last word appear in your buffer?

    What position does it land in your buffer, is it in the first spot, or in the correct idx position? 

    Is the UartRx struct a local and getting reset every time you leave the ISR?

    Maybe UartRX or some of it's Variables are being reset by some other portion of code?

    Try stepping through your code, hopefully it will help you with your debug.


    Regards,
    Cody 

  • Hi Cody, thanks.

    The problem exists even if I only send three data and the position of "0x7E" in my buffer is always the first one.
    The UartRx struct is defined only in uart.c.

    If I sent from the other device in debug mode the data array, I receive all the data. The baudrate is the same 115200.

    Regards,
    Daniel
  • Daniel,
    What is "debug mode"?

    Please use an oscilloscope to look at the Rx and Tx lines while transmitting and verify that the data is correctly being sent.

    Regards,
    Cody