Main Content

I2C Controller Read

Read data from 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 Read block

Libraries:
UAV Toolbox Support Package for PX4 Autopilots

Description

The I2C Controller Read block reads serial data from an I2C peripheral device that is connected to the board. Using this block, you can read data from 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 Normal mode simulation, the block outputs zeroes.

During Connected I/O simulation, this block reads data from the peripherals of the hardware.

Ports

Output

expand all

The port reads vector data from an I2C device that is connected to the board. The size of the data is the value that you specify in the Data size parameter.

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

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 read operation.

  • 1 for a failure in opening the bus.

  • 2 for a failure in read operation.

Data Types: uint8

Parameters

expand all

Specify the I2C bus on the board to read data from the I2C peripheral device.

Specify the I2C peripheral address to read the data. You can specify this address in hexadecimal format hex2dec(), for example, 0x20.

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 reads data from the I2C peripheral register that you specify in the Peripheral register address parameter.

Specify the I2C register address to read the data.

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

Dependencies

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

Select the data type in which you want to read from the I2C peripheral device.

Specify the data size that you want to read from the I2C peripheral device for the selected data type.

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

The port outputs one of these values:

  • 0 for a successful read operation.

  • 1 for a failure in opening bus.

  • 0 for a failure in read or write operation.

Specify how often the I2C Controller Read block reads data from the I2C peripheral device. When you specify this parameter as -1, the block inherits its sample time based on the context of the block within the model.