having trouble with aa_i2c_read() function using TotalPhase Aardvark
Show older comments
Hi,
I am able to access the .NET driver via NET.addAssembly, connect and configure the hardware as well. I can also successfully write and read data over the i2c bus, which I have verified on the oscilloscope. However, for some reason the data is not being loaded into my data_in array. Please refer to my code below. Thank you!!!
clear all
close all
try
NET.addAssembly('C:\\Matlab\i2c\total_phase\Test\aardvark_net.dll');
catch e
e.message
if(isa(e, 'NET.NetException'))
e.ExceptionObject
end
end
obj=TotalPhase.AardvarkApi;
port = 0;
bitrate = 100;
BUS_TIMEOUT = 150; % ms
%%Open the device
handle = obj.aa_open(port);
if (handle <= 0)
fprintf('Unable to open Aardvark device on port %d\n',...
port);
disp(obj.aa_status_string(handle));
return;
end
%%Ensure that the I2C subsystem is enabled
obj.aa_configure(handle, TotalPhase.AardvarkConfig.AA_CONFIG_GPIO_I2C);
%%Enable the I2C bus pullup resistors (2.2k resistors).
% This command is only effective on v2.0 hardware or greater.
% The pullup resistors on the v1.02 hardware are enabled by default.
obj.aa_i2c_pullup(handle, obj.AA_I2C_PULLUP_BOTH);
%%Power the EEPROM using the Aardvark adapter's power supply.
% This command is only effective on v2.0 hardware or greater.
% The power pins on the v1.02 hardware are not enabled by default.
obj.aa_target_power(handle,...
obj.AA_TARGET_POWER_BOTH);
%%Set the bitrate
bitrate = obj.aa_i2c_bitrate(handle, bitrate);
fprintf('Bitrate set to %d kHz\n', bitrate);
%%Set the bus lock timeout
bus_timeout = obj.aa_i2c_bus_timeout(handle, BUS_TIMEOUT);
fprintf('Bus lock timeout set to %d ms\n', bus_timeout);
%%operation here
data_in = uint8([0,0,0,0,0,0]);
device = hex2dec('1f');
data_out = [hex2dec('18'), hex2dec('c0')];
obj.aa_i2c_write(handle, uint16(device), TotalPhase.AardvarkI2cFlags.AA_I2C_NO_STOP, 2, uint8(data_out));
obj.aa_i2c_write(handle, uint16(device), TotalPhase.AardvarkI2cFlags.AA_I2C_NO_STOP, 1, uint8(hex2dec('06')));
count = obj.aa_i2c_read(handle, uint16(device), TotalPhase.AardvarkI2cFlags.AA_I2C_NO_FLAGS, 6, data_in); %
%%Close the device and exit
obj.aa_close(handle);
Answers (1)
Morten Christophersen
on 10 Feb 2014
0 votes
Hi
Have you made this work?
You should use data_in = NET.createArray('System.Byte',6)
instead of the data_in = uint8([0,0,0,0,0,0]).
However I still fail to make this work. I think that you problem lies elsewhere, however in interested if you successfully have made this work.
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!