I2C Controller Read
R2026bI2C Controller Read block

To add a block to a model, double-click the canvas and start typing the block name. Then, select the block from the list.
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
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 operation1— Failure in opening the bus2— Failure in read operation
Dependencies
To enable this parameter, select the Output error status parameter.
Data Types: uint8
Parameters
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
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)