Configuring I2C Communication
You need to have either a Total Phase Aardvark host adapter or a NI USB-845x adapter
board installed to use the i2c
interface. The following sections
describe configuration for each option.
Configuring Total Phase Aardvark
To use the I2C interface with the Aardvark adapter, you must download the Hardware Support Package to obtain the necessary files. You must also download the USB device driver from the vendor.
If you do not have the Aardvark driver installed, see Install the Total Phase Aardvark I2C/SPI Interface Support Package.
The aardvark.dll file that comes with the Total Phase Aardvark adapter board must be available in one of the following locations for use on Windows® platforms.
The location where MATLAB was started from (Bin folder).
The MATLAB current folder (PWD).
The Windows folder
C:\winnt
orC:\windows
.The folders listed in the PATH environment variable.
Ensure that the Aardvark adapter is installed properly.
instrhwinfo('i2c')
ans = HardwareInfo with properties: InstalledAdaptors: {'Aardvark' 'NI845x'} JarFileVersion: 'Version 4.1' Access to your hardware may be provided by a support package. Go to the Support Package Installer to learn more.
Look at the adapter properties.
instrhwinfo('i2c','Aardvark')
ans = HardwareInfo with properties: AdaptorDllName: 'C:\Program Files\MATLAB\R2019b\toolbox\instrument\instrumentadaptors\win64\mwaardvarki2c.dll' AdaptorDllVersion: 'Version 4.1' AdaptorName: 'Aardvark' BoardIdsInUse: [1×0 double] InstalledBoardIDs: 0 DetectedBoardSerials: {'2237482577 (BoardIndex: 0)'} ObjectConstructorName: 'i2c('Aardvark', BoardIndex, RemoteAddress);' VendorDllName: 'aardvark.dll' VendorDriverDescription: 'Total Phase I2C Driver' Access to your hardware may be provided by a support package. Go to the Support Package Installer to learn more.
You can create an I2C object using the i2c
function. The
example in the next section uses an I2C object called eeprom
that
communicates to an EEPROM chip. View the properties after creating the
object.
eeprom = i2c('aardvark',0,'50h')
I2C Object : I2C-0-50h Communication Settings BoardIndex 0 BoardSerial 2237482577 BitRate: 100 kHz RemoteAddress: 50h Vendor: aardvark Communication State Status: closed RecordStatus: off Read/Write State TransferStatus: idle
You can see that the communication settings properties reflect what was used to
create the object – BoardIndex
of 0
and
RemoteAddress
of 50h
. For information
about other properties, see Properties.
Configuring NI USB-845x
To use the I2C interface with the NI USB-845x adapter, you must download the Hardware Support Package to obtain the latest driver, if you do not already have the driver installed. If you already have the latest driver installed, you do not need to download this Support Package.
If you do not have the NI USB-845x driver installed, see Install the NI-845x I2C/SPI Interface Support Package.
Ensure that the NI USB-845x adapter is installed properly.
instrhwinfo('i2c')
ans = HardwareInfo with properties: InstalledAdaptors: {'Aardvark' 'NI845x'} JarFileVersion: 'Version 4.1' Access to your hardware may be provided by a support package. Go to the Support Package Installer to learn more.
Look at the NI USB-845x adapter properties.
instrhwinfo('i2c','NI845x')
ans = HardwareInfo with properties: AdaptorDllName: 'C:\Program Files\MATLAB\R2019b\toolbox\instrument\instrumentadaptors\win64\mwni845xi2c.dll' AdaptorDllVersion: 'Version 4.1' AdaptorName: 'NI845x' BoardIdsInUse: [1×0 double] InstalledBoardIDs: [1×0 double] DetectedBoardSerials: {0×1 cell} ObjectConstructorName: 'i2c('NI845x', BoardIndex, RemoteAddress);' VendorDllName: 'Ni845x.dll' VendorDriverDescription: 'National Instruments NI USB 845x Driver' Access to your hardware may be provided by a support package. Go to the Support Package Installer to learn more.
You can create an I2C object using the i2c
function. View the
properties after creating the object.
i2cobj = i2c('NI845x',0,'10h')
I2C Object : I2C-0-10h Communication Settings BoardIndex 0 BoardSerial 0 BitRate: 100 kHz RemoteAddress: 10h Vendor: NI845x Communication State Status: closed RecordStatus: off Read/Write State TransferStatus: idle
You can see that the communication settings properties reflect what was used to
create the object – BoardIndex
of 0
and
RemoteAddress
of 10h
. For information
about other properties, see Properties.