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);
}