How do I transfer more than 1 byte at once via SPI bus?

I believe Arduino's SPI.transfer waits to receive 8 bits after sending 8 bits.

Incorrect. With SPI, a byte is clocked in at the same time as a byte is clocked out. It may be that this byte is simply a dummy byte though, if the slave has nothing to say.

So for 24 bits, simply clock out 3 bytes without deasserting the select. Since SPI is a synchronous protocol there should be no issue with having a delay in between bytes provided the select is maintained.


In the SPI protocol, you get one byte back for every one you send. If you are not interested in the response from a device, you can just ignore the return bytes.

SPI has no handshaking. You just must send no faster than the slave device can handle. In the case of the AD5685R, that is 50 MHz.

For multibyte transfer, you keep the chip select asserted (low) between every byte by setting the transferMode to SPI_CONTINUE in the SPI.transfer call. For the last byte, you will deassert the chip select (set it high) by setting the transferMode parameter to SPI_LAST in the SPI.transfer call..


Note that there is also a version of SPI.transfer for multi-byte (buffer) transfers:

SPI.transfer(buffer, size)

I used the buffer transfer in my library for the TLC59711 (see code) and found the buffer transfer faster than transferring bytes individually using SPI.transfer(val); the switch to buffer transfers is one of the reasons my library is about 3.5 times faster than a previous library for the TLC59711.

Tags:

Spi