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.

Porting UAR to TM4C

Expert 2065 points


Hello, 

In some code I have picked from a website dedicated to STM 32 there is the code below. I was wondering how I could port it for TM4C

void USART2_IRQHandler(void)
{
	uint8_t Buffer;
	uint8_t GpsBuffer[1];
	static uint16_t Count=0;
	static uint8_t Num=0;
	uint8_t GpsFlag=1;
	if(SET==USART_GetITStatus(USART2,USART_IT_RXNE))
	{
		Buffer=USART_ReceiveData(USART2);

		if('$'==Buffer)
		{

			Num++;
			if(7==Num)//Normall output 6 NMEA sentences from GPS UART¡£
			{
				GpsBuffer[0]='$';
				Count=1;
				GpsFlag=1;
				Num=1;
			}
			else
			{
				GpsBuffer[Count++]=Buffer;
			}

		}
		else
		{
			GpsBuffer[Count++]=Buffer;
		}
	}
	USART_ClearITPendingBit(USART2, USART_IT_RXNE);//Clear interrupt
}

  • Chrischina,

    This is simply the interrupt handler and would be a very small part of the overall needs of your application since you would need to setup/configure the UARTs including enableing ineterrupts and then you would need some routines in your mainline application to process the data received and send it back out the second UART.

    However, if you were to find a project somewhere that had all the pieces you need, porting is simply replacing the chip specific drivers with the TM4C equivalent drivers or creating them by combining several TM4C APIs together to create the higher level function call. This is one method. The second would be to write an interface layer to use the device specific APIs to interface TivaWare drivers. Neither method is terribly difficult but both require some knowledge of the drivers of the device your porting from AND the drivers for the device to which you are porting to.

    Note that there are many examples within the TivaWare library that use UART to receive and transmit data. If you take a step back from the COMMAND frame of view and see the stream of data only as a sequence of bytes many of these examples will apply. Once you have captured the bytes in the right sequence, only then group them up into their respective COMMAND strings to take the appropriate action. For example, lets say bytes 0 through 2 are some sort of action command and bytes 3 through 7 are a location or address while bytes 8 though X are data and '/' 0x0A is a terminating character. Below would be some psuedo code of how to handle it.

    function GetCommand()
    x=0
    while received data != '/0x0A';
    {
    getdatabyte(data[x]);
    x = x+1;
    x>MaxDataSize?
    YES: receive error - STOP
    NO: Continue
    }

    Function ParseAndRunCommand()
    command[SizeOfCommand] = {0};
    address[4]={SizeOfAddress};
    data[MaxDataSize-SizeOfCommand-SizeOfAddress]
    command[0] = data(0)
    command[0] = data(1)
    command[0] = data(2)

    If command == 'SET'
    // get address
    address[0] = data(3)
    address[1] = data(4)
    address[2] = data(5)
    address[3] = data(6)
    // get data
    x=0;
    do while data[7+x] != '/0x0a'
    (*address+x) = data[7+x];
    x = x+1

    else if command == 'GET'
    do something related to GET operation
    else if command == 'NUL'
    do nothing

    Style points aside, this is how you would treat the incoming data stream. If you don't need to parse it, its even simpler because you just stop on the terminating char and then turn around and send the data byte by byte to the second UART and only act as a pass through.

    If there are still some questions on how to handle this, I would also suggest reaching out to your GPS supplier to see if they have some code/project that could be used as a template or at least to be studied to see how the data is handled.