I2C Master Read
Read data from I2C slave device or I2C slave device register
- Library:
UAV Toolbox Support Package for PX4 Autopilots
Description
The I2C Master Read block reads serial data from an I2C slave device that is connected to the board. Using this block, you can read data from a specific register on the I2C slave 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.
Ports
Output
Data
— Data from I2C slave device
vector
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
Status
— Status of read operation
scalar
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
I2C Bus
— I2C bus to read data
1
(default)
Specify the I2C bus on the board to read data from the I2C slave device.
Slave address
— I2C register slave address from which to read data
10
(default) | nonnegative integer
Specify the I2C slave address to read the data. You can specify this
address in hexadecimal format hex2dec()
, for example,
0x20
.
Slave byte order
— Byte ordering that your I2C slave device supports
BigEndian
(default) | LittleEndian
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.
Enable register access
— Option to read from a specific I2C slave register
on
(default) | off
When you select this parameter, the block reads data from the I2C slave register that you specify in the Slave register address parameter.
Slave register address
— The I2C slave register address to read data
2
(default) | integer between 0 and 255
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.
Data type
— Data type of data from I2C slave device
uint8
(default) | int8
| int16
| uint16
| int32
| uint32
| single
| double
Select the data type in which you want to read from the I2C slave device.
Data size (N)
— Data size to read from I2C slave device
1
(default) | nonnegative integer
Specify the data size that you want to read from the I2C slave device for the selected data type.
Output error status
— Option to display the error status during data transmission
off
(default) | on
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.
Sample time
— Frequency to read data from the I2C slave device
0.01
(default)
Specify how often the I2C Master Read block reads data from
the I2C slave device. When you specify this parameter as
-1
, the block inherits its sample time based on the
context of the block within the model.
See Also
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.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- 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)