How to communicate with multiple I2C devices within one session?
Show older comments
Hello All,
On my board there are two I2C devices: an ADC and a DAC. They are connected via one I2C bus and there are no base address conflicts. Via an Aardvark adapter and the ICT, I want to communicate with the devices within one session. What is the best way to create two I2C –object instances?
dac = i2c('aardvark',0,16);
adc = i2c('aardvark',0,76);
fopen(dac)
fopen(adc)
%write DAC
fwrite(dac,[bias 00 00])
%write control register of adc: not continuous, convert v1 v2 v3 v4
fwrite(adc,[1 95])
%write trigger register to start
fwrite(adc,[2 17])
for i=1:4
fwrite(adc,0); status = ['status : ' dec2bin(fread(adc,1))]
pause(0.5)
disp(status)
end
fclose(dac),delete(dac)
fclose(adc),delete(adc)
Doing it is similair to GPIB session with multiple instruments . However it generates an error:
Error using i2c/fopen (line 82)
Unsuccessful open: Cannot connect to the device. Possible reasons are another
application is connected, a driver is missing or the device is not available.
Error in aardvarktest2 (line 24)
fopen(adc)
Communication to each device separately is successful . But two devices in one session does not work. Anyone an idea how to communicate with two I2C devices in one session?
1 Comment
Raptrick
on 1 Apr 2016
Answers (0)
Categories
Find more on C2000 Microcontroller Blockset 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!