ArduinoCore-API icon indicating copy to clipboard operation
ArduinoCore-API copied to clipboard

SPI library does not have functions for sending or receiving data blocks

Open eurol opened this issue 7 years ago • 3 comments

SPI library does not have functions for sending or receiving data blocks. SPI.transfer has disadvantages.

  1. If I need to read from SPI a large block of data I often need to fill an array with a constant, f.e. 0xff
  2. If I need to send data block to SPI several times I must fill this array again after each sending because it is filled with data read (that I don't need anyway)

I suggest to add functions like SPI.send(void* data, size_t len, unsigned char outbyte = 0xff) and SPI.receive(void* data, size_t len)

eurol avatar Oct 10 '18 11:10 eurol

If this is implemented, I hope the API will look like an overload of SPI.transfer(const void *wr, void *rd, size_t length) which has been discussed before, where NULL is supported for the 2nd input. When SPI.h supports this, SPI_HAS_TRANSFER_BUF should be defined.

For example, the Ethernet library already has support for using this, with cores having a SPI library with this feature. https://github.com/arduino-libraries/Ethernet/blob/master/src/utility/w5100.cpp#L316

PaulStoffregen avatar Oct 10 '18 15:10 PaulStoffregen

This looks related to item (2): https://github.com/arduino/Arduino/pull/4573

per1234 avatar Oct 10 '18 16:10 per1234

Ok. Transferring can be done. But what should user do when he needs to receive a data block from a device that demands some value to continue data sending? For example device receives 0xff and continues to send data, but if it receives other byte value it stops?

eurol avatar Sep 25 '19 08:09 eurol