Skip to main content
Visitor II
November 24, 2025
Solved

I2C with IMS330dlc

  • November 24, 2025
  • 1 reply
  • 77 views

Hi

I am new to the I2C communications. I am trying to communicate to the IMS330dlc chip. I am using a lab jack U3-HV.. I am programming this via Visual Studio 2022 using c# code. I cant get back the 106 for Who am I. below is the code that I setup on a push button so I could step through the code. or if anyone has example code using Visual Studio C# 2022 please send it .

private void Read_AccelBtn_Click(object sender, EventArgs e)
{
 {
 LJUD.IO ioType = 0;
 LJUD.CHANNEL channel = 0;
 double dblValue = 0;
 double dummyDouble = 0;
 int dummyInt = 0;

 double numI2CBytesToWrite;
 double numI2CBytesToRead;
 byte[] writeArray = new byte[12];
 byte[] readArray = new byte[12];
 long i = 0;
 long serialNumber = 0;
 double slopeDACA = 0, offsetDACA = 0, slopeDACB = 0, offsetDACB = 0;
 double writeACKS = 0, expectedACKS = 0;
 numI2CBytesToWrite = 1;
 writeArray[0] = 0; //Memory address. User area is 0-63.
 //Open the LabJack.
 try
 {
 device = new U3(LJUD.CONNECTION.USB, "0", true); // Connection through USB
 }
 catch (LabJackUDException f)
 {
 showErrorMessage(f);
 }

 //Configure the I2C communication.
 //The address of the ISM330dcl on the LJTick-DAC is 0xA0.
 LJUD.AddRequest(device.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.I2C_ADDRESS_BYTE, 106, 0, 0);

 //SCL is FIO4
 LJUD.AddRequest(device.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.I2C_SCL_PIN_NUM, 4, 0, 0);

 //SDA is FIO5
 LJUD.AddRequest(device.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.I2C_SDA_PIN_NUM, 5, 0, 0);

 //See description of low-level I2C function.
 // LJUD.AddRequest(device.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.I2C_OPTIONS, 0, 0, 0);

 //See description of low-level I2C function.
 LJUD.AddRequest(device.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.I2C_OPTIONS, 4, 0, 0);

 //See description of low-level I2C function. 0 is max speed of about 130 kHz.
 LJUD.AddRequest(device.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.I2C_SPEED_ADJUST, 0, 0, 0);

 //Execute the requests on a single LabJack.
 LJUD.GoOne(device.ljhandle);

 //Get all the results just to check for errors.
 LJUD.GetFirstResult(device.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble);
 bool finished = false;
 while (!finished)
 {
 try { LJUD.GetNextResult(device.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); }
 catch (LabJackUDException f)
 {
 if (f.LJUDError == LJUD.LJUDERROR.NO_MORE_DATA_AVAILABLE)
 finished = true;
 else
 showErrorMessage(f);
 }
 }


//build write request

// Tell the labjack to cou
//tell the LabJack to count the ACK bits

// LJUD.AddRequest(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_GET_ACKS,0,0,0 );
// LJUD.AddRequest(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_WRITE);
//Execute the requests on a single LabJack.
// LJUD.GoOne(device.ljhandle);
// double dblAcks = ();
// Console write dblAcks;

// LJUD.GetResult(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_GET_ACKS, ref writeACKS);
// expectedACKS = Math.Pow(2, numI2CBytesToWrite + 1) - 1;
// if (writeACKS != expectedACKS)
// Console.Out.WriteLine("Expected ACKs = {0}, Received ACKs = {1}\n", expectedACKS, writeACKS);


numI2CBytesToWrite = 1;
writeArray[0] = 15; //Memory address. who am i.
LJUD.AddRequestPtr(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_WRITE, numI2CBytesToWrite, writeArray, 0);

LJUD.AddRequest(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_GET_ACKS, 0, 0, 0);

numI2CBytesToRead = 1;
LJUD.AddRequestPtr(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_READ, numI2CBytesToRead, readArray, 0);

//Execute the requests.
LJUD.GoOne(device.ljhandle);

//Get the result of the write just to check for an error.
LJUD.GetResult(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_WRITE, ref dummyDouble);


//Get the write ACKs and compare to the expected value. We expect bit 0 to be
//the ACK of the last data byte progressing up to the ACK of the address
//byte (data bytes only for Control firmware 1.43 and less). So if n is the
//number of data bytes, the ACKs value should be (2^(n+1))-1.
LJUD.GetResult(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_GET_ACKS, ref writeACKS);
expectedACKS = Math.Pow(2, numI2CBytesToWrite + 1) - 1;
if (writeACKS != expectedACKS)
Console.Out.WriteLine("Expected ACKs = {0}, Received ACKs = {1}\n", expectedACKS, writeACKS);

//When the GoOne processed the read request, the read data was put into the readArray buffer that
//we passed, so this GetResult is also just to check for an error.
LJUD.GetResult(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_READ, ref dummyDouble);

//Display the first 2 elements.
Console.Out.WriteLine("Read User Mem [0-1] = {0}, {1},\n\n", readArray[0], readArray[1]);

Edited to apply source code formatting - please see How to insert source code for future reference.

Best answer by Peter BENSCH

If the question is still relevant:

the IMU330DLC will only respond on I2C if a few basic points are correct, and they’re easy to miss when starting with I2C:

  1. Check the device address
    The WHO_AM_I register is at address 0x0F, but you also need the correct 7‑bit I2C slave address of the IMS330DLC (from the data sheet). In the LabJack API you must pass this slave address to the I2C command; in your snippet I only see writeArray[0] = 0; which looks like a register address, not the device address.

  2. Write then read sequence
    For WHO_AM_I you typically:
    • send a write with 1 byte: register address 0x0F,
    • then send a read of 1 byte and expect 0x6A
      Your code sets numI2CBytesToWrite = 1 and writeArray[0] = 0; this should be 0x0F, and you also need to call the LabJack I2C functions (eI2C / AddRequest + GoOne) with numI2CBytesToRead = 1

  3. Pull‑ups and wiring
    Make sure:
    • SDA/SCL are connected correctly to the LabJack
    • there are pull‑up resistors (e.g. 4.7k to 3.3V)
    • the LabJack I2C voltage matches the IMS330DLC supply (no 5V on 3.3V pins)

  4. IMU in I2C mode: check that the chip is configured for I2C (not SPI) according to its pin‑strap options

Regards
/Peter

1 reply

Peter BENSCH
Peter BENSCHBest answer
Technical Moderator
March 5, 2026

If the question is still relevant:

the IMU330DLC will only respond on I2C if a few basic points are correct, and they’re easy to miss when starting with I2C:

  1. Check the device address
    The WHO_AM_I register is at address 0x0F, but you also need the correct 7‑bit I2C slave address of the IMS330DLC (from the data sheet). In the LabJack API you must pass this slave address to the I2C command; in your snippet I only see writeArray[0] = 0; which looks like a register address, not the device address.

  2. Write then read sequence
    For WHO_AM_I you typically:
    • send a write with 1 byte: register address 0x0F,
    • then send a read of 1 byte and expect 0x6A
      Your code sets numI2CBytesToWrite = 1 and writeArray[0] = 0; this should be 0x0F, and you also need to call the LabJack I2C functions (eI2C / AddRequest + GoOne) with numI2CBytesToRead = 1

  3. Pull‑ups and wiring
    Make sure:
    • SDA/SCL are connected correctly to the LabJack
    • there are pull‑up resistors (e.g. 4.7k to 3.3V)
    • the LabJack I2C voltage matches the IMS330DLC supply (no 5V on 3.3V pins)

  4. IMU in I2C mode: check that the chip is configured for I2C (not SPI) according to its pin‑strap options

Regards
/Peter