How to clear the UART Rx Buffer and reset the pointer to first array?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

How to clear the UART Rx Buffer and reset the pointer to first array?

7,057 次查看
ericchan
Contributor I

Dear NXP Staff,

I am using LPC 54114 for software development. I try to modified the Example "usart_dma_transfer" to read in UART data array through UART_Rx pin,the data is stored in 40 bytes Rx buffer and all the 40 bytes data in the Rx buffer will sent out through UART Tx pin. (The length of data receive is shorter than 40 bytes.)

In my data Rx test (Please see attached pic.), the first data array is well received.
For second array, the data is accumulate after the first array.
After third array received, part of data is shift to next 40 bytes Rx Buffer.

My question is that , how can I clear all data in Rx Buffer after each data read and move the data pointer to the first byte of the data array, so that all new incoming data is located at the first byte of the Rx buffer?

Please advise if there are any command/instruction can do so.

My testing code is also attached for your reference.

Thanks,
Eric

0 项奖励
回复
3 回复数

7,018 次查看
marek-trmac
NXP Employee
NXP Employee

Hi Eric,

I'd recommend to use circular buffer. Circular buffer - Wikipedia 

Regards

Marek

Regards,
Marek


NOTE: If you find the answer useful, kindly click on [ACCEPT AS SOLUTION] button
0 项奖励
回复

6,985 次查看
ericchan
Contributor I

Hi Marek,

I tried to use the circular buffer, But when I read the data I found some data is not ready in the RX buffer, only first half of data is ready. I have to delay sometime and the 2nd half of data is ready in the buffer . Is there any method or status flag to read and show the 2nd half of data is ready in the buffer?

(Please see the detail in the attached picture) 

Regards,

Eric

0 项奖励
回复

6,953 次查看
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Eric,

I see you use DMA transfer, how about use DMA interrupt or flag,

after DMA finish transfer for tow data, use UART TX to send.

 

0 项奖励
回复