I'm working with the AD7746 capacitance-to-digital converter using an Arduino. Despite following the setup, the register values are not updating correctly.
Details:
Connections:
I2C address: 0x48
Confirmed connection with I2C scanner.
Setup:
Using AD7746.cpp and AD7746.h files from an I2Cdev library.
Sketch writes to configuration registers but reads back incorrect values (0x07).
Observations:
I2C communication confirmed: Scanner detects device at 0x48.
Writing Registers: Commands sent to write configuration registers (0x07, 0x09, 0x0A, 0x0B).
Reading Registers: Values read back are always 0x07.
Sample Code:
#include <Wire.h>
#include "AD7746.h"
AD7746 capSensor;
void setup() {
Serial.begin(115200);
while (!Serial);
Wire.begin();
capSensor.initialize();
if (capSensor.testConnection()) {
Serial.println("AD7746 connection successful.");
} else {
Serial.println("AD7746 connection failed.");
while (1);
}
capSensor.writeCapSetupRegister(0x81); // Example configuration
capSensor.writeExcSetupRegister(0x0B); // Example excitation setup
capSensor.writeConfigurationRegister(0x31);
capSensor.writeCapDacARegister(0x80); // Example DAC setup
readRegister(AD7746_RA_CAP_SETUP);
readRegister(AD7746_RA_EXC_SETUP);
readRegister(AD7746_RA_CONFIGURATION);
readRegister(AD7746_RA_CAP_DAC_A);
}
void loop() {
uint8_t status = capSensor.getStatus();
if (status & 0x01) { // Capacitance data ready
uint32_t capacitance = capSensor.getCapacitance();
Serial.print("Capacitance: ");
Serial.println(capacitance);
}
if (status & 0x02) { // Voltage/Temperature data ready
uint32_t vtData = capSensor.getVTData();
Serial.print("VT Data: ");
Serial.println(vtData);
}
delay(1000);
}
void readRegister(uint8_t reg) {
uint8_t value;
I2Cdev::readByte(AD7746_ADDRESS, reg, &value);
Serial.print("Read 0x");
Serial.print(value, HEX);
Serial.print(" from register 0x");
Serial.println(reg, HEX);
}
Questions:
Initialization Sequence: Are there specific steps for initializing the AD7746 that I might be missing?
Timing Issues: Could this be related to delays or timing in the I2C communication?
Power Supply: Any known issues with power requirements for the AD7746 that could cause such behavior?
Any insights or suggestions would be greatly appreciated!
Hello @Grumpy_Mike
yes, I have tried it with both 10k and 4.7k resistors. I am using this board which uses Ad7746, based on the documentation regular configuration for Ad7746 should also work for this one. But I don't know where I am going wrong that nothing happens. ( I get a constant value as output and thats it.)
Did you use those? I must say there are rather small, and the leads must be as short as possible.
It would be good to see the exact circuit you used. Is it soldered up or is it on solderless bread board? Because solderless bread board is going to give you a lot more than 2pF stray capacitance. Have you got a schematic of what you actually wired up? And also a photograph would help.
I omitted the command capSensor.writeCapSetupRegister() and nothing happened; the register values remained 0x07. I then switched to using Wire.h directly for configuration. Here is the code:
#include <Wire.h>
#define AD7745_ADDRESS 0x48 // Default I2C address for AD7745/AD7746
// AD7745/AD7746 Register addresses
#define STATUS_REG 0x00
#define CAP_DATA_HIGH 0x01
#define CAP_DATA_MIDDLE 0x02
#define CAP_DATA_LOW 0x03
#define CAP_SETUP_REG 0x07
#define VT_SETUP_REG 0x08
#define EXC_SETUP_REG 0x09
#define CONFIG_REG 0x0A
void setup() {
Serial.begin(115200);
while (!Serial) { }
Wire.begin();
// Initialize the AD7745/AD7746
initializeAD7745();
// Check if AD7745/AD7746 is connected
Wire.beginTransmission(AD7745_ADDRESS);
if (Wire.endTransmission() == 0) {
Serial.println("AD7745/AD7746 connected.");
} else {
Serial.println("AD7745/AD7746 not connected!");
while (1);
}
// Print initial register values
printRegisterValues();
}
void loop() {
// Read capacitance data
long capacitance = readCapacitance();
// Print capacitance value
Serial.print("Capacitance: ");
Serial.print(capacitance);
Serial.println(" aF");
delay(1000);
}
void initializeAD7745() {
// Reset the device to ensure it starts from a known state
Wire.beginTransmission(AD7745_ADDRESS);
Wire.write(0xBF); // Reset command
Wire.endTransmission();
delay(200); // Wait for the reset to complete
// Enable capacitive input, continuous conversion mode
Wire.beginTransmission(AD7745_ADDRESS);
Wire.write(CAP_SETUP_REG); // Point to Cap Setup Register
Wire.write(0x30); // Enable capacitive input
Wire.endTransmission();
// Set default configuration
Wire.beginTransmission(AD7745_ADDRESS);
Wire.write(CONFIG_REG); // Point to Configuration Register
Wire.write(0x10); // Set to default configuration
Wire.endTransmission();
// Setup excitation source
Wire.beginTransmission(AD7745_ADDRESS);
Wire.write(EXC_SETUP_REG); // Point to Excitation Setup Register
Wire.write(0x04); // Set excitation voltage
Wire.endTransmission();
}
long readCapacitance() {
Wire.beginTransmission(AD7745_ADDRESS);
Wire.write(CAP_DATA_HIGH); // Point to the high byte of capacitance data
Wire.endTransmission();
Wire.requestFrom(AD7745_ADDRESS, 3); // Request 3 bytes of data
while (Wire.available() < 3);
byte capHigh = Wire.read();
byte capMiddle = Wire.read();
byte capLow = Wire.read();
// Combine the three bytes to form the capacitance value
long capacitance = ((long)capHigh << 16) | ((long)capMiddle << 8) | capLow;
return capacitance;
}
void printRegisterValues() {
// Read and print Cap Setup Register
Wire.beginTransmission(AD7745_ADDRESS);
Wire.write(CAP_SETUP_REG);
Wire.endTransmission();
Wire.requestFrom(AD7745_ADDRESS, 1);
while (Wire.available()) {
byte regValue = Wire.read();
Serial.print("Cap Setup Register: 0x");
Serial.println(regValue, HEX);
}
// Read and print Configuration Register
Wire.beginTransmission(AD7745_ADDRESS);
Wire.write(CONFIG_REG);
Wire.endTransmission();
Wire.requestFrom(AD7745_ADDRESS, 1);
while (Wire.available()) {
byte regValue = Wire.read();
Serial.print("Configuration Register: 0x");
Serial.println(regValue, HEX);
}
// Read and print Excitation Setup Register
Wire.beginTransmission(AD7745_ADDRESS);
Wire.write(EXC_SETUP_REG);
Wire.endTransmission();
Wire.requestFrom(AD7745_ADDRESS, 1);
while (Wire.available()) {
byte regValue = Wire.read();
Serial.print("Excitation Setup Register: 0x");
Serial.println(regValue, HEX);
}
// Read and print Status Register
Wire.beginTransmission(AD7745_ADDRESS);
Wire.write(STATUS_REG);
Wire.endTransmission();
Wire.requestFrom(AD7745_ADDRESS, 1);
while (Wire.available()) {
byte regValue = Wire.read();
Serial.print("Status Register: 0x");
Serial.println(regValue, HEX);
}
}
Despite these changes, I still receive 0x07 for all register values.
Serial Monitor output:
11:46:58.176 -> AD7745/AD7746 connected.
11:46:58.176 -> Cap Setup Register: 0x7
11:46:58.176 -> Configuration Register: 0x7
11:46:58.176 -> Excitation Setup Register: 0x7
11:46:58.176 -> Status Register: 0x7
11:46:58.176 -> Capacitance: 458752 aF
11:46:59.175 -> Capacitance: 458752 aF
11:47:00.145 -> Capacitance: 458752 aF
11:47:01.146 -> Capacitance: 458752 aF
11:47:02.192 -> Capacitance: 458752 aF
11:47:03.190 -> Capacitance: 458752 aF
I am not using 2pF ceramic capacitor. At the moment I am just trying to drive this sensor and test it with standard capacitors. So the setup is very simple and you can see it in the attached photo:
note : I tried 10k, 4.7k resistors as pull-up resistors. Also I tried direct connection of I2C from the board to the Arduino.
I am using this board and I don't know if it adds a layer of complexity for configuration or not. since based on the schematic I2C PMOD connectors are directly connected to the AD7746's related pins
Apparently the library you are using does not send a repeated start, so obviously that library was never tested with a real device
I would look for a different library.