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.

DK-TM4C123 UART2配置问题

您好,刚开始在用DK-TM4C123G做原型系统,需要用到UART2,在例子uart_demo中将端口改动为UART2(PD6,PD7)后测试发现U2_TX管脚没有波形输出。请问是不是初始化那里不对。

//
// Enable the peripherals used by this example.
//
//ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
//ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2);

//
// Enable processor interrupts.
//
ROM_IntMasterEnable();

//
// Set GPIO A0 and A1 as UART pins.
//
//ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
ROM_GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_6 | GPIO_PIN_7);

//

// Configure the UART for 115,200, 8-N-1 operation.
//
// ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200,
// (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
// UART_CONFIG_PAR_NONE));
ROM_UARTConfigSetExpClk(UART2_BASE, ROM_SysCtlClockGet(), 9600,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));

//
// Enable the UART interrupt.
//
//ROM_IntEnable(INT_UART0);
ROM_IntEnable(INT_UART2);
//ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
ROM_UARTIntEnable(UART2_BASE, UART_INT_RX | UART_INT_RT);

//
// Prompt for text to be entered.
//
UARTSend((uint8_t *)"Enter text: ", 12);

//
// Loop forever echoing data through the UART.
//
while(1)
{
UARTSend((uint8_t *)"Enter text: ", 12);
SysCtlDelay(1000);
}

//*****************************************************************************
//
// The UART interrupt handler.
//
//*****************************************************************************
void
UARTIntHandler(void)
{
uint32_t ui32Status;

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

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

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

//*****************************************************************************
//
// Send a string to the UART.
//
//*****************************************************************************
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++);
ROM_UARTCharPutNonBlocking(UART2_BASE, *pui8Buffer++);
}
}