It should be fun,
As mentioned, the DMA operation will not speed up the actual transfers.
That is the slowest way to do things is like:
Code:
for (int i = 0; i < 1000000; i++) {
buffer[i] = SPI.transfer16(0);
}
As this code completely neuters the SPI hardware TX and RX buffers, by design, as it can only do one transfer and much wait until the system returns the actual value, before it returns,
and does not start to do anything else in SPI until the next transfer call is issued. So maybe only busy half the time.
Where as the calls like: SPI.transfer(buffer, retbuf, count);
In this case, the code will keep the 16 word TX buffer full, until the full transfer length, and it will pick off each of the return values from the SPI hardware RX buffer and place into return buffer.
So the SPI will run at the full speed. Also in this case there is also a shorter delay between words...
As I mentioned the DMA version will not be faster for the actual transfer. The main thing there is keeping the SPI doing stuff.
However where the DMA stuff makes a difference, is the actual transfer can be done with almost no overhead of the main processor. Which allows your code to do other things, like probably doing something with all of the data you are receiving.
So for example, you could setup a DMA transfer, to a logical Circular buffer. I typically end up using two DMASetting objects that are chained to each other. And I mark each of these two to interrupt me when they complete. For example, maybe each of these is sized for 4K bytes. So when the ISR is triggered, you can process the 4K bytes, while the SPI continues on to keep receiving more data in the other buffer.
Depending on how fast your process code is, that may be sufficient. If your processing code might be slower in some cases, you may need to expand on it, like maybe copy to external buffer, or maybe if fast enough in most cases, you could maybe link 4 or 8 of these buffers to each other, and hopefully the code will be able to keep up over the larger buffer.
But first baby steps.