Luka Djordjevic
Luka Djordjevic

Reputation: 21

How can I make USB-to-Serial adapter faster, ReadFile taking too long to execute

I am trying to communicate with an Arduino every 1ms. Arduino is doing just fine at sending commands but my PC wont read data every 1ms. It usually takes 3 - 4ms and by that time my Arduino has already sent a bunch of data.

I tried to use EV_RXCHAR or EV_CTS but its the same, way too much time for Windows to respond to commands.

t = clock();
ReadFile(hComm, &s, sizeof(s), &NoBytesRead, NULL);
t = clock() - t;
double time_taken = ((double)t)/CLOCKS_PER_SEC; // in seconds usualy 0.003 

I am not sure if the problem is in Windows drivers or the USB-to-UART ch340 chip.

Maybe you can recommend me some other way of doing communication at 1ms intervals?

Upvotes: 0

Views: 377

Answers (1)

Luka Djordjevic
Luka Djordjevic

Reputation: 21

Just for the future reference. The "problem" was in the USB 1.1 polling rate. Max USB 1.1 polling rate is 1000Hz so the latency of sub 1ms is just not possible with ch340 (arduino's chip)... USB 2.0 probably would work because of the 8khz polling rate.

Upvotes: 2

Related Questions