Read binary data from SPI instrument
A = read(OBJ, SIZE)
A = read(OBJ, SIZE) reads the specified number of values,
SIZE, from the SPI device connected to interface object, OBJ, and returns to A. OBJ
must be a 1-by-1 SPI interface object. By default the
precision is used.
The interface object must be connected to the device with the
connect function before any data can be read from the device,
otherwise an error is returned. A connected interface object has a
ConnectionStatus property value of
Available options for SIZE include:
N – read at most
N values into a column vector. SIZE cannot be set to
The SPI protocol operates in full duplex mode, input and output data transfers happen simultaneously. SPI communication requires N bytes of dummy data to be written into the device for reading N bytes of data from the device. The dummy data written is zeros.
For more information on using the SPI interface and this function, see Configuring SPI Communication and Transmitting Data over the SPI Interface.
To get a list of options you can use on a function, press the Tab key after entering a function on the MATLAB® command line. The list expands, and you can scroll to choose a property or value. For information about using this advanced tab completion feature, see Using Tab Completion for Functions.
This example shows how to create a SPI object
s, and read
spi object called
s = spi('aardvark', 0, 0);
Connect to the chip.
Read data from the chip.
data = read(s, 2);
Disconnect the SPI device and clean up by clearing the object.
Introduced in R2013b