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
'uint8' precision is used.
The interface object must be connected to the device with the
before any data can be read from the device, otherwise an error is
returned. A connected interface object has a
Available options for SIZE include:
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.
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
and read data.
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.