Part Number: EK-TM4C123GXL
I'm working on the EK-TM4C123GXL eval board. I'm trying to send 3 bytes via UART terminal using interrupt example: $2#.
So i made a loop as following,
do{
input[i] = UARTCharGetNonBlocking(UART0_BASE);
c = input[i];
UARTprintf("Data in c: %c\n",c);
i++;
}while(c!='#' && UARTCharsAvail(UART0_BASE));
UARTprintf("Data is received\n");
in which once user entered "#" control will come out of the loop and will print data received. But, in my case after entering "#" control is coming out of the loop but, again because of interrupt, the control goes to the handler and its printing some garbage value.(below is the screenshot)
Which is not expected. What will be the reason behind this? Why even if nothing is sent via terminal still I'm getting interrupt?
Here I'm attaching my code below. Any help or hint will be really appreciated.
Thank You.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "driverlib/sysctl.h"
#include "inc/hw_uart.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "utils/uartstdio.h"
#include "driverlib/uart.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
unsigned char c;
void UART0_Handler(void)
{
uint32_t ui32Status;
unsigned char input[3];
int i=0;
//
// Get the interrrupt status.
//
ui32Status = UARTIntStatus(UART0_BASE, true);
//
// Clear the asserted interrupts.
//
UARTIntClear(UART0_BASE, ui32Status);
//
// Loop while there are characters in the receive FIFO.
//
do{
input[i] = UARTCharGetNonBlocking(UART0_BASE);
c = input[i];
UARTprintf("Data in c: %c\n",c);
i++;
}while(c!='#' && UARTCharsAvail(UART0_BASE));
UARTprintf("Data is received\n");
}
void InitConsole(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTStdioConfig(0, 115200, 16000000);
//
// Enable processor interrupts.
//
IntMasterEnable(); //
// Enable the UART interrupt.
//
IntEnable(INT_UART0_TM4C123);
UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
}
int main()
{
InitConsole();
while(1)
{
}
}