SPIMaster_WriteThenRead Function

Header: #include <applibs/spi.h>

Performs a sequence of a half-duplex writes immediately followed by a half-duplex read using the SPI master interface. This function enables chip select once before the sequence, and disables it when it ends.

static inline ssize_t SPIMaster_WriteThenRead(int fd, const uint8_t *writeData, size_t lenWriteData, uint8_t *readData, size_t lenReadData);

Parameters

  • fd The file descriptor for the SPI master interface.

  • writeData The data to write.

  • lenWriteData The number of bytes to write.

  • readData The output buffer that receives the data. This buffer must must be large enough to receive up to lenReadData bytes.

  • lenReadData The number of bytes to read.

Return value

Returns the number of bytes transferred; or -1 for failure, in which case errno is set to the error value.

Remarks

Each call to SPIMaster_WriteThenRead is limited to at most 4096 bytes to read, and 4096 bytes to write. To transfer additional data, you need to call this function multiple times. Note that chip select will be asserted multiple times in this case.

Application manifest requirements

To access individual SPI interfaces, your application must identify them in the SpiMaster field of the application manifest.