Hi, I've been having trouble reading in data to my LabJack U6 from a 9DOF sensor stick, which has an accelerometer, magnetometer, and gyroscope built in, each of which uses I2C protocol to communicate. I tried first to configure the accelerometer, but keep running into problems with porting the pseudocode into MATLAB. I need to write data first to take the sensor out of sleep mode, but whenever I try writing any data, MATLAB encounters an internal problem and needs to close. I think it may have something to do with the data type of the array that I'm sending, but I'm not sure. Here's my code. The first part, configuring the pins and I2C options, works fine. The second part does not.
% Pin numbers scl = 1; sda = 0; % ADXL345 I2C Address 0x53 ADXL_ADDRESS = bitshift(hex2dec('53'),1); %% Open LabJack ljasm = NET.addAssembly('LJUDDotNet'); ljudObj = LabJack.LabJackUD.LJUD; [ljerror, ljhandle] = ljudObj.OpenLabJack(LabJack.LabJackUD.DEVICE.U6, ... LabJack.LabJackUD.CONNECTION.USB, '0', true, 0); %% Configure ports % Reset ports to defaults ljudObj.ePut(ljhandle, LabJack.LabJackUD.IO.PIN_CONFIGURATION_RESET, 0, 0, 0); % Configure the address byte of the chip ljudObj.AddRequest(ljhandle,LabJack.LabJackUD.IO.PUT_CONFIG, ... LabJack.LabJackUD.CHANNEL.I2C_ADDRESS_BYTE,ADXL_ADDRESS,0,0); % Configure SCL ljudObj.AddRequest(ljhandle, LabJack.LabJackUD.IO.PUT_CONFIG, ... LabJack.LabJackUD.CHANNEL.I2C_SCL_PIN_NUM,scl,0,0); % Configure SDA ljudObj.AddRequest(ljhandle, LabJack.LabJackUD.IO.PUT_CONFIG, ... LabJack.LabJackUD.CHANNEL.I2C_SDA_PIN_NUM,sda,0,0); % Configure I2C options ljudObj.AddRequest(ljhandle, LabJack.LabJackUD.IO.PUT_CONFIG, ... LabJack.LabJackUD.CHANNEL.I2C_OPTIONS,0,0,0); % Configure speed ljudObj.AddRequest(ljhandle, LabJack.LabJackUD.IO.PUT_CONFIG, ... LabJack.LabJackUD.CHANNEL.I2C_SPEED_ADJUST,0,0,0); ljudObj.GoOne(ljhandle); % Here's where problems start numWrite = 1; array = hex2dec('2D') ljudObj.AddRequest(ljhandle, LabJack.LabJackUD.IO.I2C_COMMUNICATION, ... LabJack.LabJackUD.CHANNEL.I2C_WRITE,numWrite,array,0); ljudObj.GoOne(ljhandle);
I've also tried sending the array formatted in binary, in this case 0x2D > 45 > 00101101, and it creates the same error. I would do a check for LabJack errors, but MATLAB shuts down before it returns them anyway. I'm just not sure what's wrong.
In addition, is there any easy way to configure multiple I2C address for communicating with multiple devices? I need to read from three different addresses, and I believe that means I need to reconfigure the I2C settings every time I read from a different address, is this correct? Is there a more efficient way to use multiple addresses without using low level functions?