Main Content

I2C Controller Write

Write data to I2C peripheral device or I2C peripheral device register

Add-On Required: This feature requires the UAV Toolbox Support Package for PX4 Autopilots add-on.

  • I2C Controller Write block

Libraries:
UAV Toolbox Support Package for PX4 Autopilots

Description

The I2C Controller Write block writes data to an I2C peripheral device that is connected to the board. Using this block, you can write data to a specific register on the I2C peripheral device.

To view the mapping between the Bus number and the port label on hardware board, click View I2C Bus map. For more information on the Bus mapping, see I2C Bus Port Numbers for Labels on PX4 Autopilots.

During Connected I/O simulation, this block writes data to the peripherals of the hardware.

Ports

Input

expand all

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

Output

expand all

When you select the Output error status parameter, an output port, labeled as Status, becomes available.

The port outputs one of these values:

  • 0 for a successful write operation.

  • 1 for a failure in opening the bus.

  • 2 for a failure in write operation.

Data Types: uint8

Parameters

expand all

Specify the I2C bus on the board to write data to the I2C peripheral device.

Specify the I2C peripheral address to write the data. The I2C peripheral device address is a 7-bit address.

Specify this address as an integer or in hexadecimal format by using hex2dec(), for example, 0x61.

The 2-byte ordering options are:

  • BigEndian - The most significant byte is sent first over the I2C bus.

  • LittleEndian - The least significant byte is sent first over the I2C bus.

When you select this parameter, the block writes data to the I2C peripheral register that you specify in the Peripheral register address parameter.

Specify the I2C peripheral register address to write the data.

Specify this address in 8-bit unsigned integer or in hexadecimal format. To specify the address in 8-bit unsigned integer, use uint8(), for example, ‘uint8(20)’. To specify the address in hexadecimal format, use hex2dec(), for example, 0x20.

Dependencies

This parameter appears only when you select Enable register access parameter.

When you select this parameter, an output port, labeled as Status, becomes available.

The port outputs the status of the write operation.