read
Read binary data from SPI instrument
Syntax
A = read(OBJ, SIZE)
Description
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
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
connected
.
Available options for SIZE include: N
– read at most
N
values into a column vector. SIZE cannot be set to
INF
.
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.
Note
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.
Examples
This example shows how to create a SPI object s
, and read
data.
Construct a spi
object called s
using
Vendor
'aardvark'
, with BoardIndex
of
0
, and Port
of
0
.
s = spi('aardvark', 0, 0);
Connect to the chip.
connect(s);
Read data from the chip.
data = read(s, 2);
Disconnect the SPI device and clean up by clearing the object.
disconnect(s); clear('s');
Version History
Introduced in R2013b