我需要定期接收一串长度约为45字节且波特率为115200的 RS-232数据、但 在该字符串的后面部分会丢失。
如果我接收到的字符串是"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"、我将始终获得前16个字符、这是有道理的、因为 UART FIFO 是16个字节、但我会错过许多后面的字节、例如、我可能只会从 字母的中到后部分得到几个字符。
我将执行长度 操作、以确保我尽快调用 UARTGetChar、而不会在调用时让中断发生-请查看下面的代码-但我仍然错过了数据。 如果我将速度减至9600、我似乎 不会错过任何数据、但这对于我的需求来说太慢了。
我想知道在115200不丢失数据的情况下执行此操作的唯一方法是将 DMA 与 UART 配合使用吗?
我已按如下方式配置 UART:
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // Configure the GPIO Pin Mux for RX GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0); // Configure the GPIO Pin Mux for TX GPIOPinConfigure(GPIO_PA1_U0TX); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_1); // Enable the UART module SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); while(!SysCtlPeripheralReady(SYSCTL_PERIPH_UART0)); // Configure the given serial IO port for the given baud rate and, 8-N-1 operation. UARTConfigSetExpClk(UART0_BASE, sysClockFreq, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); UARTFIFOLevelSet(UART0_BASE, UART_FIFO_TX1_8, UART_FIFO_RX1_8); // Enable the RX UART interrupt. IntEnable(INT_UART0); UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
此外、中断处理程序:
void SerialCommIntHandler(enum SERIAL_COMM_NUM serialCommNum)
{
// Get the interrupt status
uint32_t status = UARTIntStatus(UART0_BASE, true);
// Clear the asserted interrupts
UARTIntClear(UART0_BASE, status);
IntMasterDisable();
// Loop while there are characters in the receive FIFO
while(UARTCharsAvail(UART0_BASE))
{
LogInfo("%c", UARTCharGetNonBlocking(UART0_BASE));
}
IntMasterEnable();
}