Hi,
I am seeing some strange behavior when using the UART of the TM4C1237H6PZ MCU in Deep-Sleep. The module is clocked by the 16 MHz internal oscillator which is also active in Deep-Sleep. When waking up on a UART interrupt, if I immediately read the RX FIFO I always get 0x00. However, if (after checking that data is received with UARTCharsAvail) I wait some microseconds, I get the correct value. Below is the relevant code.
Kind regards
Per
static void init_uart_as_uart_master(void)
{
// Enable GPIO port
ROM_SysCtlPeripheralEnable(DEBUG_UART_PORT_PERIPHERAL);
// Enable UART peripheral
ROM_SysCtlPeripheralEnable(DEBUG_UART_PERIPHERAL);
// Set UART signals
ROM_GPIOPinTypeUART(DEBUG_UART_PORT_BASE, PIN_DEBUG_URX | PIN_DEBUG_UTX);
// Configure UART
ROM_UARTClockSourceSet(DEBUG_UART_BASE, UART_CLOCK_PIOSC);
ROM_UARTConfigSetExpClk(DEBUG_UART_BASE, MCU_PIOSC_HZ, BAUD_RATE,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
// Disable hardware flow control
UARTFlowControlSet(DEBUG_UART_BASE, UART_FLOWCONTROL_NONE);
}
static void init_uart_interrupts(void)
{
// Generate UART receive / transmit interrupts when FIFO is more than 1/8 full
ROM_UARTFIFOLevelSet(DEBUG_UART_BASE, UART_FIFO_TX1_8, UART_FIFO_RX1_8);
// Enable UART receive and receive timeout interrupts
ROM_UARTIntEnable(DEBUG_UART_BASE, UART_INT_RX | UART_INT_RT);
// Clear any pending interrupts
ROM_UARTIntClear(DEBUG_UART_BASE, UART_INT_RX | UART_INT_RT);
// Gate UART module interrupts to mcu core
ROM_IntEnable(DEBUG_UART_INT);
}
void debug_uart_isr_handler(void)
{
uint32_t status = ROM_UARTIntStatus(DEBUG_UART_BASE, true);
if ((UART_INT_RX | UART_INT_RT) & status)
{
while (ROM_UARTCharsAvail(DEBUG_UART_BASE))
{
char c;
// NB! ~5 microseconds delay is needed to get correct RX FIFO data when
// leaving deep sleep. Without this, ROM_UARTCharsAvail returns 0x00.
// This should not be needed since UARTCharsAvail returns true.
// Question to be answered by TI FAE.
mcu_wait_us_blocking(10);
c = ROM_UARTCharGetNonBlocking(DEBUG_UART_BASE);
// Send to debug channel parser
debug_parser_putc(c);
}
ROM_UARTIntClear(DEBUG_UART_BASE, UART_INT_RX | UART_INT_RT);
}
}