Best Practice Transmitting large Dataset to PC over USB Serial

Status
Not open for further replies.

luni

Well-known member
I need to transmit large blocks of measurement data to the PC as quick as possible (500 blocks, 4kB each). Data is read in from an attached spectrometer via a SPI interface in a loop.
I currently store the data points for one spectrum in a buffer (reading and storing takes about 3ms per spectrum)...
Code:
for (unsigned i = 0; i < bufferSize; i++)
{
  digitalWriteFast(CS_FIFO, LOW);
  buf[i] = SPI.transfer16(0xFFFF);
  digitalWriteFast(CS_FIFO, HIGH);
}
...and send it to the PC afterwards
Code:
stream->write(buf,buffersize);

Just wondering if it's more efficient not to buffer and do the sending directly within the read loop:
Code:
for (unsigned i = 0; i < bufferSize; i++)
{
  digitalWriteFast(CS_FIFO, LOW);
  uint16_t val = SPI.transfer16(0xFFFF);
  digitalWriteFast(CS_FIFO, HIGH);

  stream->write(((byte*)&val),2);
}

How does the UsbSerial library handle such subsequent writes? Does it collect data until a 64byte USB buffer is full or does it transmit each time write is called?

Thanks
Lutz
 
I can't answer many of your questions.

However if you use DMA to move the data and trigger it off the UART sent flag you'll be able to transfer data at the maximum rate
 
Status
Not open for further replies.
Back
Top