Skip to main content
shopping_basket Basket 0
Login

EVAL-AD7152 connected to Arduino

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

}

Upvote 0 Votes

Comments

July 6, 2020 08:34

It looks like you are missing the closing brace on your setup() function, before the definition of the readValue() function.

0 Votes

July 6, 2020 08:35

This discussion may help https://forum.arduino.cc/index.php?topic=362745.0 the title of the post appears wrong, it is an AD7152 discussion and there is some code posted towards the end which may identify an area to investigate.
There was also some non-working post covered for a different IC 7156 here
https://forum.arduino.cc/?topic=426740#msg2940911
but again may provide some ideas?
I'm new to Arduino and haven't used that chip, but have just started investigations of I2C for temperature measurements hence my general interest.

0 Votes
DesignSpark Electrical Logolinkedin