Hi,
I am searching information for reading and writing on a register using .NET component with Matlab environment.
In particular I have the slave address: 74
the register address 06
but I don't understand how to write and read from the register
Can anyone help me?
SUB20 & Matlab
Moderator: serg
Re: SUB20 & Matlab
Here is the matlab i2c sample code
Code: Select all
% Sets I2C frequency to 400kHz and writes one byte(aa) to a register(06) of
% a memory-like slave device ( bus address 74) All numbers are in hex.
NET.addAssembly('C:\Program Files\SUB-20\bin\sub20dnc.dll');
sub20 = Xdimax.Sub20();
% simulate do { ... } while(0) loop
for k=0:0
% Open first available SUB-20 device
if ~ sub20.Open(0)
break;
end
% Set I2C clock frequency to 400kHz
if ~ sub20.I2C_SetFrequency(400000)
break;
end
% Create .NET data array
Data = NET.createArray('System.Byte', 1);
% Fill up the array with data bytes to be sent
Data.Set(0, hex2dec('aa'));
% Write 'Data' array to register 6 of a device 74
if ~ sub20.I2C_Write( hex2dec('74'), hex2dec('06'), 1, Data)
break;
end
% Read register 6 of the device 74 to the array 'Data'
if ~ sub20.I2C_Read( hex2dec('74'), hex2dec('06'), 1, Data)
break;
end
end
err = sub20.GetLastError();
% Close SUB-20 device
sub20.Close()
if err > 0
fprintf('Error %d\n', sub20.GetLastError() )
error('Error!')
end
- Attachments
-
- i2c_matlab.zip
- i2c matlab sample code
- (736 Bytes) Downloaded 1077 times