Create I2C object
I2C, or Inter-Integrated Circuit, is a chip-to-chip protocol supporting two-wire
communication. An i2c
object represents a connection between MATLAB® and an I2C adapter board. Supported adapters are the Total Phase Aardvark
I2C/SPI Host Adapter and the National Instruments™ USB-845x adapter board. The adapter has one or more sensor chips connected to
it. MATLAB sends commands to the adapter board, which is the I2C master device, in order to
communicate with the chip, which is the I2C slave device. The i2c
object in
MATLAB always has the role of I2C master and cannot be used in the slave role. Use
fread
and fwrite
on the i2c
object
to communicate with the chip.
i2cobj = i2c(
creates an vendor
,boardIndex
,remoteAddress
)i2c
object associated with vendor
,
boardIndex
, and remoteAddress
.
vendor
must be either 'Aardvark'
, for
use with the Total Phase Aardvark adapter, or 'NI845x'
, for use
with the NI USB-845x adapter board. This input sets the Vendor
property.
boardIndex
specifies the board index of the adapter board
and is 0
if you have only one adapter plugged into your computer.
This input sets the BoardIndex
property.
remoteAddress
specifies the hex number address of the I2C
slave device with which to communicate and is found in documentation or data sheet
of the chip. This input sets the RemoteAddress
property.
You can communicate with multiple I2C slave devices on the same adapter using a single
i2c
object. To communicate with a different I2C slave device, first
create the object and use fopen
to open a connection to the adapter.
Then, change the RemoteAddress
property to the address of the
appropriate slave device. You can now use fwrite
and
fread
to communicate with the specified slave device. For an
example of this workflow, see Communicate with Multiple Slave Devices from NI USB-845x Adapter.