Main Content

I2C Controller Write

R2026b

Write to I2C device connected to NVIDIA Jetson board

Since R2026b

  • I2C Controller Write 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 Write block writes to an I2C peripheral device connected to an NVIDIA® Jetson™ hardware board.

Examples

Ports

Input

expand all

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

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

Output

expand all

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 write to a specific register on 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: RegisterAddressMode
Values: "on" (default) | "off"

Example: get_param(gcb,"RegisterAddressMode")

Register address the block writes to on the peripheral 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 the Enable register access parameter.

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]")

Select this parameter to send a Not Acknowledge (NACK) signal at the end of data transfer. If the block follows the NACK signal with a STOP bit, the block stops writing and releases the bus. Alternatively, if you select this parameter and select the Remove stop bit at the end of data transfer parameter, the block continues writing without releasing the bus. In this situation, the block sends a NACK signal followed by a START bit.

Dependencies

To enable this parameter, clear the Enable register access parameter.

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: NoAck
Values: "off" (default) | "on"

Example: set_param(gcb,NoAck="on")

Select this parameter to replace the STOP bit at the end of data transfer with a START bit. When the block sends a START bit, the does not release the bus and continues writing.

If you clear this parameter, the block sends a STOP bit at the end of the data transfer.

Dependencies

To enable this parameter, clear the Enable register access parameter.

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: RepeatedStart
Values: "off" (default) | "on"

Example: set_param(gcb,RepeatedStart="on")

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")

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