Write and read binary data from SPI instrument
data = writeAndRead(
writes the data
dataToWrite to the SPI instrument
s and reads the data available from the instrument as a result of
s must be a 1-by-1 SPI
interface object. Values are written and read as
The interface object must be connected to the device using the
connect function before any data can be read from the device, otherwise
an error is returned. A connected interface object has a
property value of
SPI protocol operates in full duplex mode, so input and output data transfers happen simultaneously. For every byte written to the device, a byte is read back from the device.
Write Data to and Read Data from SPI Device
This example shows how to create a SPI object
and read and write data.
spi object called
s = spi('aardvark',0,0);
Connect to the chip.
Read and write to the chip.
dataToWrite = [2 0 0 255]; data = writeAndRead(s,dataToWrite);
Disconnect the SPI device and clean up by clearing the object.
s — SPI device
SPI device, specified as an
dataToWrite — Data to write
numeric | character vector
Data to write to SPI device, specified as a row (1-by-
N-by-1) vector of numeric values or as a character vector of
text. Refer to the SPI device documentation or data sheet for more information about the
commands or data you can write to the device. You can specify data of any numeric data
type, but the data is written to the SPI device as a
Introduced in R2013b