Description

transfer() performs a simultaneous send and receive operation over the SPI bus. This is because SPI is a full-duplex protocol: while data is being sent, data is also being received.

For single-byte transfers, the received byte is returned. For two-byte transfers using transfer16(), the received two bytes are returned. For buffer transfers, the received data replaces the original content of the buffer (in-place transfer).

This function is part of the SPI library. See the SPI main page for more information.

Syntax

  • receivedVal = SPI.transfer(val)
  • receivedVal16 = SPI.transfer16(val16)
  • SPI.transfer(buffer, size)

Parameters

  • val: the byte to send over the bus. Allowed data types: byte.
  • val16: the two-byte value to send over the bus. Allowed data types: uint16_t.
  • buffer: the array of data to be transferred. Allowed data types: array of byte.
  • size: the number of bytes in the buffer to transfer. Allowed data types: size_t.

Returns

  • For SPI.transfer(val): the received byte. Data type: byte.
  • For SPI.transfer16(val16): the received two-byte value. Data type: uint16_t.
  • For SPI.transfer(buffer, size): nothing is returned; the received data is stored in buffer.