Main Content

read

Read binary data from SPI instrument

    Description

    data = read(s,count) reads the number of values specified by count from the SPI device s and returns to data. s must be a 1-by-1 SPI interface object. Values are read as uint8 data.

    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 count include: N – read at most N values into a column vector. count 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.

    example

    Examples

    collapse all

    This example shows how to create a SPI object s and read data.

    Construct an 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');

    Input Arguments

    collapse all

    SPI device, specified as an spi object.

    Number of values to read, specified as a positive integer value.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    Version History

    Introduced in R2013b