Hello,
I wrote some code that provides me possibility to communicate with PC. But my MCU response seems to be weird. Because if command is less than 8 characters everything is good. Problems appears when command is longer than 8 characters, and interrupt is called twice or more with the same value in FIFO i supposed. Result of this is i have doubled or tripled MCU response of command.
Here is my UART configuration and interrupt handler ( port A is configured in another part of code ):
void InitUART() { // running clock for uart module SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); // pin configurations GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // configuring uart to 9660 baud rate and 8n1 mode UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 9600, UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE); // running uart interrupts IntEnable(INT_UART0); UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT); }
void UARTIntHandler() { unsigned charNum = 0; int flag; // clearing interupt flags UARTIntClear(UART0_BASE, UARTIntStatus(UART0_BASE, true)); clearBuffer(); for ( charNum = 0; UARTCharsAvail(UART0_BASE); ++charNum ) { reciveBuffer[charNum] = UARTCharGetNonBlocking(UART0_BASE); } flag = CmdLineProcess(reciveBuffer); if (flag == CMDLINE_BAD_CMD) { UARTSend("Bad command.\n"); } else if ( flag == CMDLINE_TOO_MANY_ARGS ) { UARTSend("Too many arguments.\n"); } else if ( flag == CMDLINE_TOO_FEW_ARGS ) { UARTSend("Too few arguments.\n"); } else if ( flag == CMDLINE_INVALID_ARG ) { UARTSend("Invalid arguments.\n"); } }