주요 콘텐츠

I2C Controller Read

R2026b

Read from I2C device connected to NVIDIA Jetson

Since R2026b

  • I2C Controller Read block

Libraries:
NVIDIA Jetson and NVIDIA DRIVE / Communication

Description

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

The I2C Controller Read block reads from an I2C peripheral device connected to an NVIDIA® Jetson™ hardware board.

Examples

Ports

Output

expand all

Data received from device, returned as a vector or scalar. The Data type and Data size (N) parameters determine the data type and size of the vector, respectively.

Transmission status, returned as a scalar. If the transmission is successful, the block outputs 0. If the transmission generates an error, the block outputs 8.

Dependencies

To enable this port, enable Output error status.

Data Types: uint8

Parameters

expand all

To edit block parameters interactively, use the Property Inspector. From the Simulink® Toolstrip, on the Simulation tab, in the Prepare gallery, select Property Inspector.

Hardware board to deploy the model to.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

To get the block parameter value programmatically, use the get_param (Simulink) function.

Parameter: Board
Values: "NVIDIA Jetson Orin Nano Developer Kit" (default) | "NVIDIA Jetson Nano Developer Kit" | "NVIDIA Jetson Orin NX Developer Kit" | "NVIDIA Jetson Xavier NX Developer Kit" | "NVIDIA Jetson AGX Xavier Developer Kit" | "NVIDIA Jetson AGX Orin Developer Kit" | "NVIDIA Jetson TX2 Developer Kit"

Example: get_param(gcb,"Board")

I2C module to use on the board.

The setting for the Board parameter determines the available settings for this parameter and its programmatic parameter settings. This table shows the available I2C Module parameter settings and programmatic parameter names for each board:

Board Parameter SettingAvailable I2C Module Parameter SettingsProgrammatic Parameter Name
  • NVIDIA Jetson Orin™ Nano

  • NVIDIA Jetson Orin NX

  • NVIDIA Jetson AGX Orin

  • 1

  • 7

I2CModule_1_7
  • NVIDIA Jetson TX2

  • NVIDIA Jetson Nano

  • 0

  • 1

I2CModule_0_1
  • NVIDIA Jetson Xavier NX

  • NVIDIA Jetson AGX Xavier

  • 1

  • 8

I2CModule_1_8

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

To get the block parameter value programmatically, use the get_param (Simulink) function.

Parameter: I2CModule_1_7
Values: "7" (default) | "1"

Example: get_param(gcb,"I2CModule_1_7")

Parameter: I2CModule_0_1
Values: "0" (default) | "1"

Example: get_param(gcb,"I2CModule_0_1")

Parameter: I2CModule_1_8
Values: "8" (default) | "1"

Example: get_param(gcb,"I2CModule_1_8")

Address of the peripheral device on the I2C module.

Tips

To obtain the device address, use the scanI2CBus function. For example, for a live connection object named hwObj, enter:

addresses = scanI2CBus(hwObj);
addresses{:}
ans = 

  struct with fields:

        Bus: 'i2c-1'
    Devices: {'74'}


ans = 

  struct with fields:

        Bus: 'i2c-8'
    Devices: {'74'}

The function returns addresses in the hexadecimal format. Convert the address to decimal format by using the hex2dec function. For example, to connect to the device at hexadecimal address 74, set Peripheral address to hex2dec("74").

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

To get the block parameter value programmatically, use the get_param (Simulink) function.

Parameter: SubAddress
Values: "10" (default) | positive integer in quotes

Example: set_param(gcb,SubAddress="116")

Example: set_param(gcb,SubAddress=string(hex2dec("74"))) sets the address to the hexadecimal value 74.

Order in which to transmit bytes between the Jetson board and the peripheral device.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

To get the block parameter value programmatically, use the get_param (Simulink) function.

Parameter: SubByteOrder
Values: "BigEndian" (default) | "LittleEndian"

Example: set_param(gcb,SubByteOrder="LittleEndian")

Select this parameter to specify the register to read from on the device.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

To get the block parameter value programmatically, use the get_param (Simulink) function.

Parameter: RegisterAddressMode
Values: "on" (default) | "off"

Example: get_param(gcb,"RegisterAddressMode")

Register address that the block reads from on the device, specified as a nonnegative integer scalar or a 2-element vector. Each element must be between 0 and 255.

For devices that use 1-byte register addressing, specify the register address as a scalar. For devices that use 2-byte register addressing, specify the register address as a 2-element vector, where each element represents one byte of the address.

Dependencies

To enable this parameter, select Enable register access.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

To get the block parameter value programmatically, use the get_param (Simulink) function.

Parameter: RegisterAddress
Values: "0" (default) | nonnegative integer or 2-element vector in quotes

Example: set_param(gcb,"RegisterAddress","7")

Example: set_param(gcb,"RegisterAddress","[1 2]")

Data type of the output signal.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

To get the block parameter value programmatically, use the get_param (Simulink) function.

Parameter: SubDataType
Values: "uint8" (default) | "int8" | "int16" | "uint16" | "int32" | "uint32" | "single" | "double"

Example: set_param(gcb,SubDataType="uint16")

Size of the data that the block reads from the I2C device at each time step. The block reads N elements of the data type specified by the Data type parameter from the device.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

To get the block parameter value programmatically, use the get_param (Simulink) function.

Parameter: DataLength
Values: "1" (default) | positive integer in quotes

Example: set_param(gcb,DataLength="3")

Select this parameter to output the error status of the data transfer.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

To get the block parameter value programmatically, use the get_param (Simulink) function.

Parameter: OutputStatus
Values: "off" (default) | "on"

Example: get_param(gcb,"OutputStatus")

Sample time, in seconds, at which the block reads data from the I2C device. If Sample Time is -1, Simulink automatically chooses a sample time for the block.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

To get the block parameter value programmatically, use the get_param (Simulink) function.

Parameter: SampleTime
Values: "-1" (default) | numeric scalar in quotes

Example: get_param(gcb,"SampleTime")

Extended Capabilities

expand all

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced in R2026b

See Also

Functions

Blocks