How to read LDC1314 with I2C

I have referred the data sheet and successfully configure the register.But when I use Wire function to read the data through serial port, it turned out to be 0xffff(65535) all the time.I have checked my hardware connection and it is all right...Maybe there’s something wrong with my code but I can’t find it.
Here is my code.

#include<Wire.h>
int LDC = 0x2A;
int CH0DATA = 0x00;
int CH1DATA = 0x02;
int CH2DATA = 0x04;
int CH3DATA = 0x06;

word test;

unsigned long ini_0 = 0,ini_1 = 0,ini_2 = 0,ini_3 = 0;

word readValue(int LDC,int reg)
{
int a = 0,b = 0;
word val = 0;
Wire.beginTransmission(LDC);
Wire.write(reg);

Wire.endTransmission(LDC);
Wire.requestFrom(LDC,2);
while(Wire.available())
{
a = Wire.read();
b = Wire.read();
}
val = a;
val<<=8;
val+=b;
test = a;
return val;

}

unsigned long readChannel0()
{
unsigned long val = 0;
word a = 0;
a = readValue(LDC,CH0DATA);
val = a;
return val;
}
unsigned long readChannel1()
{
unsigned long val = 0;
word a = 0;
a = readValue(LDC,CH1DATA);
val = a;
return val;
}
unsigned long readChannel2()
{
unsigned long val = 0;
word a = 0;
a = readValue(LDC,CH2DATA);
val = a;
return val;
}
unsigned long readChannel3()
{
unsigned long val = 0;
word a = 0;
a = readValue(LDC,CH3DATA);
val = a;
return val;
}

void writeConfig(int LDC,int reg,int MSB,int LSB)

{
Wire.beginTransmission(LDC);
Wire.write(reg);
Wire.write(MSB);
Wire.write(LSB);
Wire.endTransmission();
}

void Configuration()
{
writeConfig(LDC,0x14,0x10,0x05);//CLOCK_DIVIDERS_CH0
writeConfig(LDC,0x1E,0x60,0x00);//DRIVE_CURRENT_CH0
writeConfig(LDC,0x10,0x00,0x0A);//SETTLECOUNT_CH0
writeConfig(LDC,0x08,0x04,0xD6);//RCOUNT_CH0
writeConfig(LDC,0x0C,0x29,0xFF);//OFFSET0

writeConfig(LDC,0x15,0x10,0x05);//CLOCK_DIVIDERS_CH1
writeConfig(LDC,0x1F,0x70,0x00);//DRIVE_CURRENT_CH1
writeConfig(LDC,0x11,0x00,0x0A);//SETTLECOUNT_CH1
writeConfig(LDC,0x09,0x04,0xD6);//RCOUNT_CH1
writeConfig(LDC,0x0D,0x29,0xFF);//OFFSET1

writeConfig(LDC,0x16,0x10,0x05);//CLOCK_DIVIDERS_CH2
writeConfig(LDC,0x20,0x70,0x00);//DRIVE_CURRENT_CH2
writeConfig(LDC,0x12,0x00,0x0A);//SETTLECOUNT_CH2
writeConfig(LDC,0x0A,0x04,0xD6);//RCOUNT_CH2
writeConfig(LDC,0x0E,0x29,0xFF);//OFFSET2

writeConfig(LDC,0x17,0x10,0x05);//CLOCK_DIVIDERS_CH3
writeConfig(LDC,0x21,0x60,0x00);//DRIVE_CURRENT_CH3
writeConfig(LDC,0x13,0x00,0x0A);//SETTLECOUNT_CH3
writeConfig(LDC,0x0B,0xFF,0xFF);//RCOUNT_CH3
writeConfig(LDC,0x0F,0x29,0xFF);//OFFSET3

writeConfig(LDC,0x18,0x00,0x01);//STATUS
writeConfig(LDC,0x1A,0x00,0x00);//CONFIG
writeConfig(LDC,0x19,0x00,0x00);//ERROR_CONFIG
writeConfig(LDC,0x1B,0xC2,0x0C);//MUX_CONFIG
writeConfig(LDC,0x1C,0x06,0x00);//RESET_DEVICE
}

void Caliberate()
{
ini_0 = readChannel0();
ini_1 = readChannel1();
ini_2 = readChannel2();
ini_3 = readChannel3();
}

void ldc_init()
{
Wire.begin();
Configuration();
delay(500);
Caliberate();
}
void setup()
{
Serial.begin(9600);
void ldc_init();
}
void loop()
{
unsigned long data0 =5;
unsigned long data1 = readChannel1();
unsigned long data2 = readChannel2();
unsigned long data3 = readChannel3();
Serial.print("test:");
Serial.print(data0);
data0 = readValue(LDC,0x7f);
Serial.print("CH0:");
Serial.print(data0);
Serial.print(" CH1:");
Serial.print(data1);
Serial.print(" CH2:");
Serial.print(data2);
Serial.print(" CH3:");
Serial.println(data3);
delay(500);
}

Which Arduino board do you use ?
That is a 3.3V chip and the Arduino Uno is a 5V Arduino board.
Can you give a link to the LDC1314 module that you bought ? Or do you use the bare chip ?

The combination of LDC1314 and Arduino is rare. I could only find this: https://hackaday.io/project/19243-ldc1314-breakout.
This is not Arduino code, but it is readable: https://github.com/michael-hao/ldc1314/blob/master/User/ldc1314.c

When you use the "REPLY" button, there is a < / > button on the left above the text field. That is for the code tags. When you put your sketch between < code > and < / code > then it is easier to read for us.

Why do you make "readChannel0()" functions, when all it does is "readValue(LDC,CH0DATA)" ? You might just as well use the "readValue()" functions.

In the datasheet is a warning that the sensor will go nuts with wrong pulses on the I2C bus. Do you have short wires, to avoid noise on the I2c bus ? What value are your pullup resistors ?

Could you add a test, to check the I2C bus every time in ldc_init() ?

void ldc_init()
{
  Wire.begin();

  Wire.beginTransmission( LDC);
  byte error = Wire.endTransmission();
  if( error == 0)
  {
    Serial.println( "LDC1314 sensor found");
  }
  else
  {
    Serial.println( "Warning, sensor not found");
  }

  Configuration();
  delay(500);
  Caliberate();
}

You could add another test. For example in the loop() read the DEVICE_ID every time the loop() runs and check if that is correct.

It could be a misconfiguration. But first I want to be sure that the I2C communication is running.

Can you take another look at your sketch ? Please don't use the same name for global variables and parameters.
I also prefer names that are longer. For example "lcd1314Address" for the I2C address and perhaps "DATA0register" for the register address of "DATA0".

The datasheet shows a "repeated start" between writing the register address and reading the data. You could add that to your code.

Could you write a function that uses a unsigned 16 bits parameter and writes the MSB and LSB to the sensor ?

Thank you very much for your reply!
I have found where my problem is and now I have got it over.As you said,I checked my “ldc_init() “ function and “readValue” function and I finally found I misused Wire.endTranmission(),I put an extra parameter into it so the I2C is closed after I write the register ‘s address.Now I can read the data normally!
For it’s my first time using this forum so I’m very sorry to trouble you with my awful code, next time I’ll use the method(Although I still did’t find the button on iPad website, maybe I can try another time on PC).

You can also type the code tags: [ code ] and [ / code ]
Type them without spaces.

codetags.png

Are you using a 5V Arduino board with a 3.3V sensor ?

No, I connected VCC with 3.3V pin.I have referred the data sheet.

When you use a 5V Arduino board (for example the Arduino Uno, Nano, Mega 2560, Leonardo) with a 3.3V sensor, the signals might not match. It is possible that the 5V I2C bus raises the SDA and SCL voltage levels above 3.3V. Some sensors can take a little more voltage, but some sensors do get damaged.

What value are your pullup resistors ?
Are you using a 5V Arduino board with a 3.3V sensor ?
Which Arduino board do you use ?
Can you give a link to the LDC1314 module that you bought ? Or do you use the bare chip ?