主要内容

readRegister

Read register of I2C device connected to NVIDIA Jetson

Since R2026a

    Description

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

    data = readRegister(i2cObj,regAddress) reads a single uint8 value from the register address, regAddress, of the I2C device i2cObj.

    example

    data = readRegister(i2cObj,regAddress,dataPrecision) reads the value from the register as the data type dataPrecision.

    data = readRegister(___,registerAddressWidth=width) specifies the width of the register address in bytes.

    example

    Examples

    collapse all

    This example shows how to read from a specified 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.

    Read from register 7 on the I2C device. In this example, the register returns 43. The value depends on the state of your hardware.

    readRegister(i2cObj,7)
    ans =
    
      uint8
    
       43

    Read from register 256 on the device. Because the address is greater than 255, the address width is 2 bytes. Specify the registerAddressWidth as "2Byte".

    readRegister(i2cObj,256,registerAddressWidth="2Byte")
    ans =
    
      uint8
    
       42

    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 type, specified as "uint8", "int8", "uint16", "int16", "uint32", "int32", "uint64", or "int64".

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

    Output Arguments

    collapse all

    Data read from the I2C device, returned as a scalar. The dataPrecision argument determines the data type of the output data.

    Version History

    Introduced in R2026a

    See Also

    Objects

    Functions