Main Content


Write binary data to SPI instrument



    write(s,data) writes the data, data, to the SPI instrument s. s must be a 1-by-1 SPI interface object. You can specify data as any numeric data type, but the data is written to the SPI device as a uint8 value.

    The interface object must be connected to the device with the connect function before any data can be read from or written to the device, otherwise an error is returned. A connected interface object has a ConnectionStatus property value of connected.

    The SPI protocol operates in full duplex mode, input and output data transfers happen simultaneously. For every byte written to the device, a byte is read back from the device. This function will automatically flush the incoming data.


    collapse all

    This example shows how to create a SPI object s and read and write 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.


    Write to the chip.

    dataToWrite = [2 0 0 255];

    Disconnect the SPI device and clean up by clearing the object.


    Input Arguments

    collapse all

    SPI device, specified as an spi object.

    Data to write to SPI device, specified as a row (1-by-N) or column (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 uint8 value.

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

    Version History

    Introduced in R2013b