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.
Hi,
I am new to Tiva-C hardware, especially peripheral such as UART. The example project uart_echo works as expected. I would like to add UART1 to this project. The first step I want UART1 in loopback mode. Whenever a character is received in UART0, it sends to both UART0 and UART1. Here is the interrupt vector table.
IntDefaultHandler, // GPIO Port A IntDefaultHandler, // GPIO Port B IntDefaultHandler, // GPIO Port C IntDefaultHandler, // GPIO Port D IntDefaultHandler, // GPIO Port E UARTIntHandler, // UART0 Rx and Tx IntDefaultHandler, // for FIFO new usage UARTInt1Handler, // UART1 Rx and Tx
The main code is shown below.
int main(void) { // // Set the clocking to run directly from the crystal at 120MHz. // g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Enable the GPIO port that is used for the on-board LED. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); // // Enable the GPIO pins for the LED (PN0). // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0); // // Enable the peripherals used by this example. // ??????? ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1); // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // // Enable processor interrupts. // ROM_IntMasterEnable(); // // Set GPIO A0 and A1 as UART pins. // GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Configure the UART for 115,200, 8-N-1 operation. // ROM_UARTConfigSetExpClk(UART0_BASE, g_ui32SysClock, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); ROM_UARTConfigSetExpClk(UART1_BASE, g_ui32SysClock, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); // // Enable the UART interrupt. // ROM_IntEnable(INT_UART0); ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT); // // This register write will set the UART to operate in loopback mode. Any // data sent on the TX output will be received on the RX input. // HWREG(UART1_BASE + UART_O_CTL) |= UART_CTL_LBE; ROM_IntEnable(INT_UART1); ROM_UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT); // // Prompt for text to be entered. // UARTSend((uint8_t *)"\033[2JEnter text: ", 16); // // Loop forever echoing data through the UART. // while(1) { } }
After it receives one character, it goes to the default handler:
static void IntDefaultHandler(void) { // // Go into an infinite loop. // while(1) { } }
If I disable UART1 interrupt by commenting either line of
ROM_IntEnable(INT_UART1);
ROM_UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT);
UART0 will work as normal. That is, introducing UART1 makes the program jump to the the default interrupt handler.
I don't know what part of UART1 configuration wrong. Can you tell me the problem?
Thanks,
Sorry, I forget to add UART interrupt routine. It will be almost complete with it. It sends received character to both UART0 and UART1.
void UARTIntHandler(void) { uint32_t ui32Status; int32_t rcv_char; // // 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. // #if 0 ROM_UARTCharPutNonBlocking(UART0_BASE, ROM_UARTCharGetNonBlocking(UART0_BASE)); #else rcv_char = ROM_UARTCharGetNonBlocking(UART0_BASE); ROM_UARTCharPutNonBlocking(UART0_BASE, rcv_char); #endif // write UART1 ROM_UARTCharPutNonBlocking(UART1_BASE, rcv_char); // // Blink the LED to show a character transfer is occuring. // GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, GPIO_PIN_0); // // Delay for 1 millisecond. Each SysCtlDelay is about 3 clocks. // SysCtlDelay(g_ui32SysClock / (1000 * 3)); // // Turn off the LED // GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0); } }