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)...
...and send it to the PC afterwards
Just wondering if it's more efficient not to buffer and do the sending directly within the read loop:
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 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);
}
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