Data broken huge data stream receiving in USART (MF)

Hi, all

I’m trying to solve stream-broken in usart through MF.

Through usart bus, 21760 bytes as speed of 250kbps should be transferred. When I tested with netduino based PK with large buffer(I modified RxQueue to receive all data), sometimes data is missing. Every time the index of missing is changing, so I think it is not related with logic in C# app.

Below is a part of netduino source related with USART.

I thought it is related with AddCharToRxBuffer, so I used this test code in Keil with debugger.
(the length of data is fixed, so I used MAX_STRLEN for checking stream is finished)

When I confirm the data in received_string array while PC is hang in else condition, the data is different with original one.

Now I am suppose it is timing issue.

  • Usart Interrupt Clock or
  • Thread/Timer issue related with other core function or

I’m not expert in native and embedded, so I’m checking every module one by one. I wonder which part can be related with this issue.

P.S. I tested also native example, and it works. So this is not hardware problem.

Jiwon

@ Jiwon -

I think your first code is correct, you just need to check the buffer size to make sure there is no overload.

Your second code, I think you will be lost at least 1 byte at (cnt == MAX_STRLEN)

and,

char c = (char)(uart->DR); // read RX data
received_string[cnt] = (char)(uart->DR);

Some register will reset or change its value after you read it. Not sure UART->DR does or not. but it should be:

char c = (char)(uart->DR); // read RX data
received_string[cnt] =c;

Just share what I think

Thanks, Dat

As you said, the second one can makes trouble. Actually, I didn’t test it, cause that it just mistake while I edit the code for post.

Anyway, I already increased the buffer size over what I expected through Portking Kit.

Now, I’m trying to solve it through interop way and facing other issue.

Really thanks for sharing, Dat.

I choose the way of reading data corretly as interop and used polling method in there. I could check it works good through debugger. If I tried to do it within managed code, many things are interfere with each other, so I cannot make sure which part affect the problem.

I solved the problem using interop, and it is the fastest way. Usart thread can be blocked by other function. Interop operates in single thread and suspend managed code. If you want to do almost real-time and high speed data process, interop(or RLP - I’ve not used RLP yet) will be helpful.