主要内容

writeRegister

Write to register of I2C device connected to NVIDIA Jetson board

Since R2026a

    Description

    Add-On Required: This feature requires the MATLAB Coder Support Package for NVIDIA Jetson and NVIDIA DRIVE Platforms add-on.

    writeRegister(i2cObj,regAddress,data) writes the data, data, as a uint8 value to the register address, regAddress, of the I2C device i2cObj.

    example

    writeRegister(i2cObj,regAddress,data,dataPrecision) writes in the data type dataPrecision.

    writeRegister(___,registerAddressWidth=width) specifies the register address width of the register to write to.

    example

    Examples

    collapse all

    This example shows how to write to a specific register of an I2C device connected to an NVIDIA® Jetson™ board.

    Create a jetson object namedhwObj. Use the scanI2CBus function to scan the I2C buses on the Jetson board. In this example, the Jetson board has two I2C buses, i2c-1 and i2c-8. Each bus has a device at address 0x74.

    hwObj = jetson;
    addresses = scanI2CBus(hwObj);
    Devices on i2c-1: 74.
    Devices on i2c-8: 74.

    Create an i2cdev object, i2cObj, connecting to the device on the i2c-1 bus.

    i2cObj = i2cdev(hwObj,"i2c-1",0x74);
    Connected to device at address 116 on bus i2c-1.

    Write the value 42 to the register 7. By default, the Jetson board writes the value as a uint8 data type.

    regAddress = 7;
    writeRegister(i2cObj,regAddress,42);

    Write the value 42 to the address 256. Because the address is greater than 255, its width is two bytes. Specify the width as "2Byte".

    regAddress = 256;
    writeRegister(i2cObj,regAddress,42,registerAddressWidth="2Byte");
    

    Input Arguments

    collapse all

    Connection to the I2C device, specified as an i2cdev object.

    Register address, specified as a nonnegative integer. The address can be at most 255 if width is "1Byte" and at most 65335 if width is "2Byte".

    Data to write to the I2C device, specified as a vector.

    Data type, specified as "uint8", "int8", "uint16", "int16", "uint32", "int32", "uint64", or "int64".

    Register address width, specified as "1Byte" or "2Byte".

    Version History

    Introduced in R2026a

    See Also

    Objects

    Functions