Main Content

write

Write data to I2C peripheral device

Since R2023a

    Description

    example

    write(peripheral,data) writes the row or column vector data to the I2C peripheral device peripheral.

    example

    write(peripheral,data,datatype) writes data in the form specified by datatype, regardless of the format in data.

    Examples

    collapse all

    Connect to an I2C peripheral device on an NI™ USB-845x controller and write data to it.

    Connect to the NI USB-845x using its serial number. In this example, the NI USB-845x controller board that is connected to the computer has the serial number 01F26E0A.

    controller = ni845x("01F26E0A");

    Connect to an I2C peripheral device on the controller board. In this example, the peripheral has an address of 0x48.

    peripheral = device(controller,I2CAddress="0x48");

    Write the values [1,2,3,4,5] to the I2C peripheral device as uint8 values.

    write(peripheral,1:5)

    Input Arguments

    collapse all

    I2C peripheral device, specified as a device object.

    Example: write(peripheral,data) writes data to the I2C peripheral device object peripheral connected to an Aardvark™ or NI USB-845x controller.

    Data to write to the I2C peripheral device, specified as a row (1-by-N) or column (N-by-1) vector of numeric values or as a character vector or string scalar of text. Refer to the peripheral device documentation or data sheet for more information about the commands or data you can write to the peripheral device.

    Example: write(peripheral,1:5) writes the values [1,2,3,4,5].

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

    Size and format of each value, specified as a character vector or string. datatype determines the number of bytes to write for each value and the interpretation of those bytes as a MATLAB® data type. For ASCII text, you can specify datatype as "char".

    Example: write(peripheral,data,"uint32") writes the data as uint32.

    Data Types: char | string

    Version History

    Introduced in R2023a