Part Number:EK-TM4C1294XL
Hi, so I have to use multiple UART ports for my project - one of which I will wait for a key word and respond with a corresponding string. I am having two main problems:
My receive function only will receive only 6 characters without messing up - I can work around this and make all keywords only 6 characters max but I think there is a bigger underlying issue which I need to watch out for. I am kind of stuck and I am not sure where my errors are any advice, help or pointing in some direction would be very appreciated
void EnableUART0(void) { // // Enable GPIO and UART 0 // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); // // Configure UART Pins for UART MODE // GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTClockSourceSet(UART0_BASE, UART_CLOCK_SYSTEM); UARTConfigSetExpClk(UART0_BASE, g_ui32SysClock, 115200, UART_CONFIG_WLEN_8 | UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE); IntRegister(INT_UART0, UART0Get); IntEnable(INT_UART0); UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT); } void UART0print(const char* text) { const char* p; // Iterate over each character of `text`, // until we reach the NUL terminator for (p = text; *p != '\0'; p++) { // Pass each character to some function UARTCharPut(UART0_BASE, *p); } } void UART0Get(void) { int i = 0; // if (UARTCharsAvail(UART0_BASE) == true) while(UARTCharsAvail(UART0_BASE)) { Incoming1[i] = UARTCharGetNonBlocking(UART0_BASE); ++i; // int i; // for(i=0;i<21;i++) // maybe change 21 to something more realistic in the future >>> // { // Incoming1[i] = UARTCharGetNonBlocking(UART0_BASE); // } } }
The issue I am referring to is with regards to the UART0Get function - which will only work for 6 characters max without an issue, slightly beyond 6 characters for example 7, it will eliminate the first character and print out the last 6 for example if I send "1234567" it will only store "234567". If I send something much larger than 6 then it acts very randomly, I do not understand what is happening.
In my main function I am trying to get it to recognize that I send the word "Temp" and it should reply back with an arbitrary string value I am using for now during testing:
int main(void) { g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); FPUEnable(); //FPURoundingModeSet(FPU_ROUND_POS_INF); IntMasterEnable(); // Enable the processor to respond to interrupts. //configureUARTTesting(); EnableUART0(); while(1) { UART0print(Incoming1); if (strcmp(Incoming1,"Temp") == 0) { UART0print(TempValue); // UART0print(Incoming1); } // UART0print(Test); // UART0print(Line); // UART0print(Incoming1); // UART0print(Line); // UART0print(Inductance); // UART0print(Line); // UART0print(Frequency); // UART0print(Line); } }
TempValue is just a string variable I had saved earlier and looks like this
char TempValue[] = "50 Deg";
Incoming1 is just a char array meant to store the incoming chars sent in over UART and is defined as follows
char Incoming1[15];
In the beginning I had tried to keep Incoming1 an array without a set number of spaces but that caused even more problems, which seemed to go away when I typed a value into Incoming1 such as 15 in this case.