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.

UART

Other Parts Discussed in Thread: TM4C129XNCZAD

Hi Forum,

              This is Santosh here. I am working on tm4c129xnczad 32 bit controller and i am very new to it.I am facing problem with UART. I am using UAR in interrupt mode and written handlers for all the UART's i.e UART0 -UAR7 but i am using UART0 and UART5. i hav connected rovinc wifi rn - 171 wifi module to the controller.UART0 to UARt7 send functions are also written. I am sending $$$ command on UART5 to the wifi module the wifi module in return responds with CMD . inside the this response i am receiving on uart5 only an storing it in buffer. this buffer i am sending on UART0 and verifying it in docklight. i need  to recheck this response. So what i am doing is i am checking the receiving  buffer locations 0 1 and 2 for C M and C .The command i am sending before the continous loop[ i.e before while(1) and oly once.. this check i am doing after sending the command. if there is a match i send C again on UART0 and if there is no match i am sending F on uart0.The problem i am facing is after i dump the code into the controller the F comes first on the docklight on UARt0 and the later CMD response from wifi comes which is not the way i wanted .As per the flow of execution the finishing the call then oly the condition check should happen but it is happening the other way around. Please help with this problem for your reference i am posting the code also. will be waiting for a response at the earlier

Regards

Santosh Prasad S


#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_nvic.h"
#include "inc/hw_gpio.h"
#include "driverlib/flash.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "driverlib/emac.h"
#include "driverlib/uart.h"
#include "drivers/pinout.h"
#include "drivers/touch.h"
#include "string.h"
#include "inc/tm4c129xnczad.h"

void uarthandler1(void);
void uarthandler2(void);
void uarthandler3(void);
void uarthandler4(void);
void uarthandler5(void);
void uarthandler6(void);
void uarthandler7(void);

void delay(int);
void wifi(void);


//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif

//*****************************************************************************
//
// The UART interrupt handlers.
//
//*****************************************************************************

// THIS IS FOR UART0
char buffer[300] = {0} ;
char buffer1[300];
char flag = 0;
char *cmd1 = "$$$";
unsigned char cmd_counter = 0;
int l = 0,i = 0,k = 0,loop = 0,loop1 = 0;

UART0_IntHandler(void)
{
uint32_t ui32Status;

//
// Get the interrrupt status.
//
ui32Status = ROM_UARTIntStatus(UART0_BASE, true);

//
// Clear the asserted interrupts.
//
ROM_UARTIntClear(UART0_BASE, ui32Status);

//
// Loop while there are characters in the receive FIFO.
//
while(ROM_UARTCharsAvail(UART0_BASE))
{
//
// Read the next character from the UART and write it back to the UART.
//
ROM_UARTCharPutNonBlocking(UART0_BASE,
UARTCharGetNonBlocking(UART0_BASE));

}
}

UART1_IntHandler(void)
{
uint32_t ui32Status;

//
// Get the interrrupt status.
//
ui32Status = ROM_UARTIntStatus(UART1_BASE, true);

//
// Clear the asserted interrupts.
//
ROM_UARTIntClear(UART1_BASE, ui32Status);

//
// Loop while there are characters in the receive FIFO.
//
while(ROM_UARTCharsAvail(UART1_BASE))
{
//
// Read the next character from the UART and write it back to the UART.
//
ROM_UARTCharPutNonBlocking(UART1_BASE,
UARTCharGetNonBlocking(UART1_BASE));
}
}
UART2_IntHandler(void)
{
uint32_t ui32Status;

//
// Get the interrrupt status.
//
ui32Status = ROM_UARTIntStatus(UART0_BASE, true);

//
// Clear the asserted interrupts.
//
ROM_UARTIntClear(UART2_BASE, ui32Status);

//
// Loop while there are characters in the receive FIFO.
//
while(ROM_UARTCharsAvail(UART2_BASE))
{
//
// Read the next character from the UART and write it back to the UART.
//
ROM_UARTCharPutNonBlocking(UART2_BASE,
UARTCharGetNonBlocking(UART2_BASE));
}
}
UART3_IntHandler(void)
{
uint32_t ui32Status;

//
// Get the interrrupt status.
//
ui32Status = ROM_UARTIntStatus(UART3_BASE, true);

//
// Clear the asserted interrupts.
//
ROM_UARTIntClear(UART3_BASE, ui32Status);

//
// Loop while there are characters in the receive FIFO.
//
while(ROM_UARTCharsAvail(UART3_BASE))
{
//
// Read the next character from the UART and write it back to the UART.
//
ROM_UARTCharPutNonBlocking(UART3_BASE,
UARTCharGetNonBlocking(UART3_BASE));
}
}
UART4_IntHandler(void)
{
uint32_t ui32Status;

//
// Get the interrrupt status.
//
ui32Status = ROM_UARTIntStatus(UART4_BASE, true);

//
// Clear the asserted interrupts.
//
ROM_UARTIntClear(UART4_BASE, ui32Status);

//
// Loop while there are characters in the receive FIFO.
//
while(ROM_UARTCharsAvail(UART4_BASE))
{
//
// Read the next character from the UART and write it back to the UART.
//
ROM_UARTCharPutNonBlocking(UART4_BASE,
UARTCharGetNonBlocking(UART4_BASE));
}
}
UART5_IntHandler(void)
{
uint32_t ui32Status;

//
// Get the interrrupt status.
//
ui32Status = ROM_UARTIntStatus(UART5_BASE, true);

//
// Clear the asserted interrupts.
//
ROM_UARTIntClear(UART5_BASE, ui32Status);

//
// Loop while there are characters in the receive FIFO.
//
while(ROM_UARTCharsAvail(UART5_BASE))
{
//
// Read the next character from the UART and write it back to the UART.
//
ROM_UARTCharPutNonBlocking(UART0_BASE,
UARTCharGetNonBlocking(UART5_BASE));
}
}
UART6_IntHandler(void)
{
uint32_t ui32Status;

//
// Get the interrrupt status.
//
ui32Status = ROM_UARTIntStatus(UART6_BASE, true);

//
// Clear the asserted interrupts.
//
ROM_UARTIntClear(UART6_BASE, ui32Status);

//
// Loop while there are characters in the receive FIFO.
//
while(ROM_UARTCharsAvail(UART6_BASE))
{
//
// Read the next character from the UART and write it back to the UART.
//
ROM_UARTCharPutNonBlocking(UART6_BASE,
UARTCharGetNonBlocking(UART6_BASE));
}
}
UART7_IntHandler(void)
{
uint32_t ui32Status;

//
// Get the interrrupt status.
//
ui32Status = ROM_UARTIntStatus(UART7_BASE, true);

//
// Clear the asserted interrupts.
//
ROM_UARTIntClear(UART7_BASE, ui32Status);

//
// Loop while there are characters in the receive FIFO.
//
while(ROM_UARTCharsAvail(UART7_BASE))
{
//
// Read the next character from the UART and write it back to the UART.
//
ROM_UARTCharPutNonBlocking(UART7_BASE,
UARTCharGetNonBlocking(UART7_BASE));
}
}

//*****************************************************************************
//
// Send a string to the UART.
//
//*****************************************************************************
/*
//THIS IS FOR UART0
void
UARTSend(const uint8_t *pui8Buffer, uint32_t ui32Count)
{
//
// Loop while there are more characters to send.
//
while(ui32Count--)
{
//
// Write the next character to the UART.
//
ROM_UARTCharPutNonBlocking(UART0_BASE, *pui8Buffer++);
}
}
*/
void UART0Send(const uint8_t *pui8Buffer, uint32_t ui32Count)
{
//
// Loop while there are more characters to send.
//
while(ui32Count--)
{
//
// Write the next character to the UART.
//
ROM_UARTCharPutNonBlocking(UART0_BASE, *pui8Buffer++);
}
}
void UART1Send(const uint8_t *pui8Buffer, uint32_t ui32Count)
{
//
// Loop while there are more characters to send.
//
while(ui32Count--)
{
//
// Write the next character to the UART.
//
ROM_UARTCharPutNonBlocking(UART1_BASE, *pui8Buffer++);
}
}
void UART2Send(const uint8_t *pui8Buffer, uint32_t ui32Count)
{
//
// Loop while there are more characters to send.
//
while(ui32Count--)
{
//
// Write the next character to the UART.
//
ROM_UARTCharPutNonBlocking(UART2_BASE, *pui8Buffer++);
}
}
void UART3Send(const uint8_t *pui8Buffer, uint32_t ui32Count)
{
//
// Loop while there are more characters to send.
//
while(ui32Count--)
{
//
// Write the next character to the UART.
//
ROM_UARTCharPutNonBlocking(UART3_BASE, *pui8Buffer++);
}
}
void UART4Send(const uint8_t *pui8Buffer, uint32_t ui32Count)
{
//
// Loop while there are more characters to send.
//
while(ui32Count--)
{
//
// Write the next character to the UART.
//
ROM_UARTCharPutNonBlocking(UART4_BASE, *pui8Buffer++);
}
}
void UART5Send(const uint8_t *pui8Buffer, uint32_t ui32Count)
{
//
// Loop while there are more characters to send.
//
while(ui32Count--)
{
//
// Write the next character to the UART.
//
ROM_UARTCharPut(UART5_BASE, *pui8Buffer++);
//
// ROM_UARTCharPut
}
}
void UART6Send(const uint8_t *pui8Buffer, uint32_t ui32Count)
{
//
// Loop while there are more characters to send.
//
while(ui32Count--)
{
//
// Write the next character to the UART.
//
ROM_UARTCharPutNonBlocking(UART6_BASE, *pui8Buffer++);
}
}
void UART7Send(const uint8_t *pui8Buffer, uint32_t ui32Count)
{
//
// Loop while there are more characters to send.
//
while(ui32Count--)
{
//
// Write the next character to the UART.
//
ROM_UARTCharPutNonBlocking(UART7_BASE, *pui8Buffer++);
}
}

void uarthandler2(void)
{
uint32_t ui32Status2;

//
// Get the interrrupt status.
//
ui32Status2 = ROM_UARTIntStatus(UART2_BASE, true);

//
// Clear the asserted interrupts.
//
ROM_UARTIntClear(UART2_BASE, ui32Status2);

//
// Loop while there are characters in the receive FIFO.
//
while(ROM_UARTCharsAvail(UART2_BASE))
{
//
// Read the next character from the UART and write it back to the UART.
//
ROM_UARTCharPutNonBlocking(UART2_BASE,
UARTCharGetNonBlocking(UART2_BASE));
}
}

*/
void uarthandler4(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))
{
//
// Read the next character from the UART and write it back to the UART.
//
ROM_UARTCharPutNonBlocking(UART4_BASE,
UARTCharGetNonBlocking(UART4_BASE));
}
}
void uarthandler5(void)
{
uint32_t ui32Status5;

//
// Get the interrrupt status.
//
ui32Status5 = ROM_UARTIntStatus(UART5_BASE, true);

//
// Clear the asserted interrupts.
//
ROM_UARTIntClear(UART5_BASE, ui32Status5);

//
// Loop while there are characters in the receive FIFO.
//
while(ROM_UARTCharsAvail(UART5_BASE))
{

buffer[k] = ROM_UARTCharGetNonBlocking(UART5_BASE);//buffer[k] = UARTCharGet(UART5_BASE);//
ROM_UARTCharPutNonBlocking(UART0_BASE,buffer[k]);// ROM_UARTCharPut(UART0_BASE,buffer[k]);//
k++;
// l++;

}
}

}
void uarthandler7(void)
{
uint32_t ui32Status7;

//
// Get the interrrupt status.
//
ui32Status7 = ROM_UARTIntStatus(UART7_BASE, true);

//
// Clear the asserted interrupts.
//
ROM_UARTIntClear(UART7_BASE, ui32Status7);

//
// Loop while there are characters in the receive FIFO.
//
while(ROM_UARTCharsAvail(UART7_BASE))
{
//
// Read the next character from the UART and write it back to the UART.
//
ROM_UARTCharPutNonBlocking(UART7_BASE,
UARTCharGetNonBlocking(UART7_BASE));
}
}

//*****************************************************************************
//
// This example demonstrates how to send a string of data to the UART.
//
//*****************************************************************************
void delay(int num)
{
for(loop = 0;loop < num;loop++)
{
for(loop1 = 0;loop1 < 200000;loop1++);
}
}

int
main(void)
{
uint32_t ui32SysClock;
ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), 120000000);

//
// Configure the device pins.
//

PinoutSet();

ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP);

//THIS IS FOR UART0
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
//THIS IS FOR UART1
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
//THIS IS FOR UART2
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2);
//THIS IS FOR UART3
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3);
//THIS IS FOR UART4
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART4);
//THIS IS FOR UART5
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART5);
//THIS IS FOR UART6
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART6);
//THIS IS FOR UART7
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART7);
// Enable processor interrupts.

//
// Configure the UART for 115,200, 8-N-1 operation.
//

// THIS IS FOR UART0 and baudrate 115200

ROM_UARTConfigSetExpClk(UART0_BASE, ui32SysClock, 9600,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));

//THIS IS FOR UART1
ROM_UARTConfigSetExpClk(UART1_BASE, ui32SysClock, 9600,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));

//THIS IS FOR UART2
ROM_UARTConfigSetExpClk( UART2_BASE, ui32SysClock, 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));

//THIS IS FOR UART3
ROM_UARTConfigSetExpClk( UART3_BASE, ui32SysClock, 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));

//THIS IS FOR UART4
ROM_UARTConfigSetExpClk( UART4_BASE, ui32SysClock, 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));

//THIS IS FOR UART5
ROM_UARTConfigSetExpClk( UART5_BASE, ui32SysClock, 9600,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));

//THIS IS FOR UART6
ROM_UARTConfigSetExpClk( UART6_BASE, ui32SysClock, 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));

//THIS IS FOR UART7
ROM_UARTConfigSetExpClk(UART7_BASE, ui32SysClock, 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));

//
// Enable the UART interrupt.
//

// THIS IS FOR UART 0
ROM_IntEnable(INT_UART0);
UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);


//THIS IS FOR UART5
ROM_IntEnable(INT_UART5);
ROM_UARTIntEnable(UART5_BASE, UART_INT_RX | UART_INT_RT);
UARTIntRegister(UART5_BASE,uarthandler5);


//
// Prompt for text to be entered.
//
IntMasterEnable();

wifi();

if((flag == 1) && (buffer[0] == 'C'))
{
delay(100);
UART0Send((uint8_t *)"C",1);
delay(100);
flag = 0;
}
else if((flag == 0) && (buffer[0] != 'C'))
{
delay(100);
UART0Send((uint8_t *)"F",1);
delay(100);
}


while(1)
{


}
}

void wifi(void)
{
delay(100);
UART5Send((uint8_t *)"$$$",3);
delay(5);
flag = 1;

}

  • santosh prasad s said:

    Please help with this problem for your reference i am posting the code also. will be waiting for a response at the earlier

     Hi Santosh, from your text is difficult to understand what you ask for, please try reword and split in simple phrases.

    It is better to use the function insert file than post a so long code text, forum is more readable and file can be uploaded.