Main Content

Transition Your Code to aardvark or ni845x Interface

The i2c function, its object functions, and its properties will be removed. Use the device function with an aardvark or ni845x object instead.

Discover I2C Controllers

This example shows how to discover I2C controllers physically connected to your machine using the recommended functionality.

FunctionalityUse This Instead
aaInfo = instrhwinfo("i2c","Aardvark");
aaList = aardvarklist;
niInfo = instrhwinfo("i2c","NI845x");
niList = ni845xlist;

For more information, see aardvarklist and ni845xlist.

Find Existing I2C Controller Connections

instrfind and instrfindall will be removed. Use ni845xfind and aardvarkfind instead. (since R2024a)

Connect to I2C Controller and Peripheral Device

The fopen function is not available in the updated interface. The object creation functions aardvark, ni845x, and device create the object and connect the object to the I2C controller or peripheral device, as shown in the table.

FunctionalityUse This Instead
a = i2c("Aardvark",0,80);
fopen(a)
a = aardvark(aaList.SerialNumber(1));
d = device(a,I2CAddress=80);
n = i2c("NI845x",0,80);
fopen(n)
n = ni845x(niList.SerialNumber(1));
d = device(n,I2CAddress=80);

For more information, see aardvark, ni845x, and device.

Write and Read Binary or String Data

These examples show how to perform a binary write and read, how to write nonterminated string data, and how to write and read fixed-length string data, using the recommended functionality.

FunctionalityUse This Instead
% a is an i2c object
fwrite(a,0:8,"uint8");
data = fread(a,8,"uint8")
data =

     1
     2
     3
     4
     5
     6
     7
     8

Same for object n.

% d is a device object
write(d,0:8,"uint8");
data = read(d,8,"uint8")
data =

     1     2     3     4     5     6     7     8

% a is an i2c object
fwrite(a,[0 'hello'],"char");

Same for object n.

% d is a device object
write(d,[0 'hello'],"char");
% a is an i2c object
fwrite(a,0,"char");
data = fread(a,5,"char");
data = char(data)'
data =

    'hello'

Same for object n.

% d is a device object
write(d,0,"char");
data = read(d,5,"char")
data =

    'hello'

For more information, see write or read.

Disconnect I2C Controller Connections

The fclose function is not available in the updated interface. To disconnect i2c controller connections, use clear or delete instead, depending upon whether you are working in a single workspace or multiple workspaces. For details, see the following examples on the interface reference pages:

See Also

| |

Related Topics