我能讀取數據正常。數據是一系列記錄,每個記錄以「\ r \ n」作爲終止符結尾,然後數據流以「\ r \ n」結尾。第一條記錄完美,但其餘記錄缺少第一個X字符。 X也不會改變。數據來自調制解調器。我錯過了這個例程以讀取AVR上的uart數據
c = UART0_RxChar();
response[0]=c;
i=0;
rec=0;
while((c=UART0_RxChar()) != CR)
{
response[i++]=c;
while ((c=UART0_RxChar()) != CR)
{
response[i++]=c;
}
rec++;
UART1_Printf("Record %d %s", rec, response);
UART1_Printf("\n\n");
memset(response,0,strlen(response));
i=0;
AT_ASSERT(UART0_RxChar() == LF)
}
AT_ASSERT(UART0_RxChar() == LF)
// Finished
壞數據接收
Record 1 7854122,4,2017-04-11 00:00,2017-04-11 8:09,29342441,,,,,,,0,0,0,0,
Record 2 705-03 13:15,18958737,TRK 23564,,,,BOL 327867,,0,0,0,0,
Record 3 7,BOL 327867,,0,0,0,0,
Record 4 717-05-03 23:59,38580000,TRK 23564,,,,BOL 327867,,0,0,0,0,
Record 5 7,BOL 327867,,0,0,0,0,
Record 6 717-05-05 23:59,86340000,TRK 23564,,,,BOL 327867,,0,0,0,0,
Record 7 7,BOL 327867,,0,0,0,0,
實際數據
7854122,4,2017-04-11 00:00,2017-04-11 08:09,29342441,,,,,,,0,0,0,0,
7854122,1,2017-04-11 08:09,,0,,,,,,,0,0,0,0,
7854122,4,2017-05-03 08:00,2017-05-03 13:15,18958737,TRK 23564,,,,BOL 327867,,0,0,0,0,
7854122,1,2017-05-03 13:15,2017-05-03 13:16,70332,TRK 23564,,,,BOL 327867,,0,0,0,0,
7854122,3,2017-05-03 13:16,2017-05-03 23:59,38580000,TRK 23564,,,,BOL 327867,,0,0,0,0,
7854122,3,2017-05-04 00:00,2017-05-04 23:59,86340000,TRK 23564,,,,BOL 327867,,0,0,0,0,
好吧,我認爲這正是問題所在,但我從未在avr上設置過接收緩衝區。我正在研究。 – Eddie