I saw a few other posts on this forum mentioning similar issues, but could not find a definitive answer anywhere.
My init code for the UART is as follows:
// Note: It does not matter which UART I use. I tried 0 thru 7, and they all do the same thing.
#define PC_UART_SYSCTL SYSCTL_PERIPH_UART3
#define PC_UART_BASE UART3_BASE
SysCtlPeripheralEnable(PC_UART_SYSCTL);
while (!SysCtlPeripheralReady(PC_UART_SYSCTL))
{
}
UARTDisable(PC_UART_BASE);
UARTConfigSetExpClk(PC_UART_BASE, getSystemClockFreqHz(), PC_UART_BAUD_RATE,
( UART_CONFIG_WLEN_8
| UART_CONFIG_STOP_ONE
| UART_CONFIG_PAR_NONE));
This seems to match the code in the Programming Example section of the TivaWare manual.
Later on, I do a loopback test on the UART:
bool passed = true; // must disable before changing settings UARTDisable(PC_UART_BASE); // put UART into loopback mode PlaceUARTLoopback(PC_UART_BASE, 1); // clear any pending rx errors UARTIntClear(PC_UART_BASE, 0xffffffffu); UARTRxErrorClear(PC_UART_BASE); UARTEnable(PC_UART_BASE); UARTCharPut (PC_UART_BASE, 0x5a); value = UARTCharGet(PC_UART_BASE); passed = (value == 0x5a); if (passed) { *puStatus &= ~POST_UART_LOOPBACK; } else { *puStatus |= POST_UART_LOOPBACK; } UARTDisable(PC_UART_BASE); PlaceUARTLoopback(PC_UART_BASE, 0);
The loopback test usually fails (although it will intermittently pass).
If I single step through the init code using the CCS debugger, I see that after calling UARTConfigSetExpClk(),the UART's RX error status register shows both a break and a framing error, and the data register contents are 0x0500. If I continue stepping, after a few instructions the errors get cleared and the DR goes to 0x0000.
However, if I just run to the loopback test without stepping, the errors are still set and the DR still contains 0x0500. Even after calling UARTRxErrorClear() in the loopback test code, the error bits remain set, causing the test to fail.
I also discovered that if I add a 100 ms delay before calling the loopback test, then things work fine.
It appears that there is some sort of time lag before the contents of the UART control registers arrive at the proper state. Is there something I am neglecting to do in setting up the UART?
Regards,
Dave