Hello everyone, I am using EVAL-AD7152 to get the capacitance data from a 2pF ceramic capacitor, but the Arduino can not read the capacitance value of AD7152, I use 3.3V arduino mega2560 as my master device, and my slave device is 3.3V. Below is my code.
#include <Wire.h>
Â
#define AD7152_I2C_ADDRESS 0x48Â Â Â Â Â Â Â Â Â Â Â Â Â Â //AD7152 adress
#define AD7152_REG_STATUS 0x00
#define AD7152_REG_CH1_DATA_MSB 0x01
#define AD7152_REG_CH1_DATA_LSB 0x02
#define AD7152_REG_CH2_DATA_MSB 0x03
#define AD7152_REG_CH2_DATA_LSB 0x04
#define AD7152_REG_CH1_SETUP 0x0B
#define AD7152_REG_CONFIGURATION 0x0F
#define AD7152_REG_CONFIGURATION_2 0x1A
#define AD7152_REG_CapDACplus 0x11
#define AD7152_REG_CapDACminus 0x12
Â
#define RESET_ADDRESS 0xBF
Â
byte myArray[] = {219, 0, 0, 0, 49, 0, 255};Â Â Â //SETUP Reg, x, x, x, CONFIG REg
Â
void writeRegister(uint8_t reg, uint16_t value)
{
 Wire.begin();
 Wire.beginTransmission(AD7152_I2C_ADDRESS);
 Wire.write(reg);
 Wire.write(value);
 Wire.endTransmission();
 delay(4); //Wait a little bit that the change is effective
}
Â
unsigned char readRegister(uint8_t reg)
{
 unsigned char val;
 Wire.beginTransmission(AD7152_I2C_ADDRESS);
 Wire.write(reg); // register to read
 Wire.endTransmission();
Â
 Wire.requestFrom(AD7152_I2C_ADDRESS, 1); // read a byte
Â
Â
Â
 while(Wire.available()==0) {
val = Wire.read();
 return val;
}
Â
void setup()
{
 Serial.begin(9600);
 Serial.println("Initializing");
Â
 Wire.begin();
 Wire.beginTransmission(AD7152_I2C_ADDRESS);
Â
Wire.endTransmission(); // ends i2c cycle
 delay(1);
 Serial.println("setup end");
Â
unsigned char readValue() {
 unsigned char ret = 0;
Â
 unsigned char status = 0;
Â
 unsigned char value = readRegister(AD7152_REG_CH1_SETUP);
ret = value;
Â
 return ret;
}
Â
void loop()
{
  unsigned char status = readValue();
 Â
  Serial.println("I2C Communication problem....!");
Â
  Serial.println(status, HEX);
  Serial.println(status, HEX);
  Serial.println(status, HEX);
Â
 Â
  delay(1000);
}