主要内容

I2C Controller Read

R2026b

Read data from I2C peripheral device or device register

Since R2026b

  • I2C Controller Read block

Libraries:
UAV Toolbox Support Package for ArduPilot Autopilots / Peripheral Blocks

Description

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

The I2C Controller Read block reads serial data from an I2C peripheral device connected to the board.

Use this block to:

  • Communicate with I2C peripheral devices on ArduPilot autopilot hardware.

  • Read data from specific registers on I2C peripheral devices. To read from a specific register, enable the Enable register access parameter.

To view the mapping between the bus numbers and the port labels on hardware board, click View I2C Bus map.

Simulation Behavior:

  • Normal mode simulation — The block outputs zeros.

  • Connected I/O simulation — The block reads data from the peripheral devices connected to the hardware.

Ports

Output

expand all

This port outputs vector data from an I2C device connected to the board. The Data size parameter determines the size of the output vector.

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

The port outputs one of these values:

  • 0 — Successful read operation

  • 1 — Failure in opening the bus

  • 2 — Failure in read operation

Dependencies

To enable this parameter, select the Output error status parameter.

Data Types: uint8

Parameters

expand all

Specify the I2C bus on the board to read data from the I2C peripheral device. To view the mapping between the bus number and the port label on your hardware board, click View I2C Bus map.

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
Values: 1 (default) | positive integer
Data Types: numeric

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

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: SlaveAddress
Values: integer
Data Types: uint8

Specify the byte ordering used when interpreting multi-byte data.

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

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

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: SlaveByteOrder
Values: BigEndian | LittleEndian
Data Types: char | string

Select this parameter to enable reading data from a specific register in the peripheral device. When enabled, the Peripheral register address parameter becomes available.

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 | off
Data Types: logical

Specify the I2C register address from which the data is read. Specify this address as an integer or in hexadecimal format by using hex2dec(), for example, hex2dec('20') for address 0x20.

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: uint8 scalar
Data Types: uint8 | string

Select the data type of the output signal. The block interprets the bytes read from the peripheral based on the selected data type.

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: SlaveDataType
Values: uint8 | int8 | int16 | uint16 | int32 | uint32 | single | double
Data Types: character vector | string

Specify the number of data elements to read from the I2C peripheral device. The total number of bytes read depends on both this parameter and the Data type parameter. For example, if data type is uint16 and data size is 3, the block reads six bytes and outputs a vector of three uint16 values.

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: positive integer
Data Types: uint8

Select this parameter to enable the Status output port.

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: on | off
Data Types: logical

Specify the time between consecutive reading of 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.

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) | positive scalar
Data Types: double

Version History

Introduced in R2026b

See Also

Blocks