LPC1769 UART读取混杂在一起



i具有连接到LPC1769的GPS模块。当我的软件读取它们时,它们通常会像这样弄乱:

[gps] Parsing: GPGGA,021447.80$GPGGA,021448.800,,,,,0,0,,,M,,M,,*4B
[gps] Parsing: GPGSA,A,1,,,,,,,,,,,,,,,*1E
[gps] Parsing: GPGSV,1,1,00*79
[gps] Parsing: GPRMC,021448.800,V,,,,,0.00,0.00,060180,,,N*41
[gps] Parsing: GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
[gps] GPS location: 231200246:21448, no fix
[gps] Parsing: GPGGA,021449.80$GPGGA,021450.800,,,,,0,0,,,M,,M,,*42
[gps] Parsing: GPGSA,A,1,,,,,,,,,,,,,,,*1E
[gps] Parsing: GPRMC,021450.800,V,,,,,0.00,0.00,060180,,,N*48
[gps] Parsing: GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
[gps] GPS location: 45200246:21450, no fix
[gps] Parsing: GPGGA,021451.80$GPGGA,021452.800,,,,,0,0,,,M,,M,,*40
[gps] Parsing: GPGSA,A,1,,,,,,,,,,,,,,,*1E
[gps] Parsing: GPRMC,021452.800,V,,,,,0.00,0.00,060180,,,N*4A
[gps] Parsing: GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
[gps] GPS location: 135200246:21452, no fix

每个批次的第一句话以16个字节开头(总是16个字节;我的代码在解析前吞下了初始$)。我的代码看起来像这样:

void gps_task(void) {
    char buffer[128], *ptr;
    locupd_packet_t loc;
    for (;;) {
        while (Uart_ReadChar(3) != '$');
        ptr = buffer;
        while ((*ptr++ = Uart_ReadChar(3)) != 'n');
        *(ptr - 1) = 0;
        Log_Debug("Parsing: %s", buffer);
        // Parse buffer
        Zeptos_Sleep(1000);
    }
}

如果我删除睡眠,问题只会发生在第一个更新中,那么所有其他问题都可以读取正常。这是ReadChar代码:

char Uart_ReadChar(int uartn) {
    LPC_UART_TypeDef *uart = uarts[uartn];
    uint32_t status;
    while (((status = uart->LSR) & 1) == 0) {
        if (status & (1 << 1)) Log_Error("RX buffer overflow on UART %i", uartn);
        Zeptos_BlockOnIrq(UART0_IRQn + uartn);
    }
    return uart->RBR & 0xff;
}

当适当的UART IRQ开火时,BlockOnIrq呼叫返回。我检查是否有溢出,但没有发生。要注意的要点:

  • uart fifo恰好也是16个字节
  • 更新为1Hz,021447等是时间戳,因此可以看到所有其他更新都已完全阅读,其中中间的更新在某个地方丢失了

似乎您似乎仅在接收缓冲区为空时检查溢出。在阅读RBR寄存器之前,请尝试检查cicle之后的溢出。

相关内容

  • 没有找到相关文章

最新更新