Main Content

writeRegister

Write data to I2C peripheral device register

Since R2023a

    Description

    example

    writeRegister(peripheral,registerAddress,data) writes the values of data as uint8 to the specified register memory address registerAddress of the I2C peripheral device peripheral. This operation is done in a single I2C transaction.

    writeRegister(peripheral,registerAddress,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 a register on 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 value 10 to the register at address 1 as uint8 values.

    writeRegister(peripheral,1,10);

    Input Arguments

    collapse all

    I2C peripheral device, specified as a device object.

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

    Register address to write to on the I2C peripheral device, specified as a number. Refer to the peripheral device documentation or data sheet for more information about valid register addresses.

    Example: writeRegister(peripheral,1,data) writes to a register at address 1.

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

    Data to write to the register of 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.

    Example: writeRegister(peripheral,registerAddress,5) writes the value 5 to a register.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | 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: writeRegister(peripheral,registerAddress,data,"uint32") writes data to a register as uint32.

    Data Types: char | string

    Version History

    Introduced in R2023a