Description
This version of transfer:
void transfer(void *_bufout, void *_bufin, size_t _count, SPITransferMode _mode = SPI_LAST)
Has been removed form 2.7.0.
The API is important for several reasons and should be restored in an improved form. See below for an API common in other board support packages.
The Arduino Standard array API, void transfer(void *buf, size_t count)
is not suitable for many applications.
-
buf
will be overwritten. This means you must copybuf
to tmp array if it is must not be overwritten. -
Some devices such as SD cards in SPI mode are full duplex examine the data stream so you must fill
buf
with a value. Typically this is 0XFF or 0X00. -
The remaining transfer(buf, count) is not DMA. This can be very slow. See my logic analyzer trace of 2.7.0. It's about 1/4 as fast as DMA for this case.
-
Here is a version of transfer that is common with several vendors that solves the above problems and provides send only and receive only by using
nullptr
for either the send or receive buffer. An async callback mode would be nice but is optional.
SPI.transfer(const void* tx_buffer, void* rx_buffer, size_t length, callback_t myFunction = nullptr)
tx_buffer: array of Tx bytes that is filled by the user before starting the SPI transfer. If nullptr, default dummy 0xFF bytes will be clocked out.
rx_buffer: array of Rx bytes that will be filled by the slave during the SPI transfer. If nullptr, the received data will be discarded.
length: number of data bytes that are to be transferred
myFunction: user specified function callback to be called after completion of the SPI DMA transfer. It takes no argument and returns nothing, e.g.: void myHandler(). Can be nullptr if not using a callback.
NOTE: tx_buffer and rx_buffer sizes MUST be identical (of size length)
Metadata
Metadata
Assignees
Labels
Type
Projects
Status