Maybe I’m too dumb, but I do not really understand the way the SPI Master Driver function NaSpiReadWrite is supposed to work.
In which way can I control, how many bytes to send and how many bytes to receive, if there’s only one length that I can specify. Maybe I want to send 3 bytes, but want to read 10. How should I do this?

If I would control the SPI without that function, but only using the corresponding ARM registers, how much slower would it be (with no DMA used)?


There is only one length because the bytes are transmitted and received at the same time.

How you want it to run depends a bit on how the other end works. Assuming you send 3 bytes as a command, and then get 10 bytes as a response you need to use 13 byte buffers for both Tx and Rx.

Set up the 3 Tx bytes in the low order of the Tx buffer, and fill the rest with zero or FF
Start the Transfer.
The SPI Clock starts and the three bytes are clocked out, and first three bytes of Rx buffer get random data, Then the next 10 bytes send whatever is filled in the Tx buffer, but the Rx buffer is being filled with the 10 bytes that are now coming back.

Hope this helps

That is because the SPI is operated through DMA. The processor is set up to do it this way so that the read/write operation can be done in hardware. If you truly want to do it byte by byte (really inefficient), you can set a length of 1, then keep a index to know what to do.


OK, thanks to your replies I do understand the function now. But I do observe, that it is really slow. Using a logic analyzer I can see, that it takes really long before the DMA transfer actually starts.
So to me it seems, that NASpiReadWrite may be OK for large transfers, but for small transfers its really inefficient. I also tried to do the transfer without the use of NASpiReadWrite and DMA, but by using the serial port control and status registers and the FIFO data register directly. This does work fine, but is obviously slow for larger transfers. Is it possible to mix the use of NASpiReadWrite and using the registers directly assuming I have only one SPI slave device?


I also found the problem of being slow for small transfers. There is a thread in the forum about this at,2742#8806

This may help