Hi All,
I am trying to interface an arduino UNO with an AD7746 over I2C. Currently i have a simple script to write to the configuration register and then read back the configuration:
#include <Wire.h>
#define I2C_ADDRESS 0x48
void setup() {
Wire.begin();
Serial.begin(9600);
}
uint8_t readI2C(byte reg) {
Wire.beginTransmission(I2C_ADDRESS);
Wire.write(reg);
Wire.endTransmission();
Wire.requestFrom(I2C_ADDRESS, 1);
uint8_t value = 0;
if(Wire.available()) {
value = Wire.read();
}
return value;
}
bool writeI2C(byte reg, byte data) {
Wire.beginTransmission(I2C_ADDRESS);
Wire.write(reg);
Wire.write(data);
int error = Wire.endTransmission();
if(error == 0)
return true; // success
else
return false; // failure
}
void loop() {
bool writeResult = writeI2C(0x09, 0x10);
Serial.print("Write to 0x09: ");
Serial.println(writeResult ? "Success" : "Failure");
delay(300);
uint8_t data = readI2C(0x09);
Serial.print("Read 0x09: ");
Serial.println(data, HEX);
delay(100);
}
The problem I have is that the code is able to read from the register perfectly fine but the value I read after the write function does not match the value that should have been written. It is almost like the register is read only.
According to the datasheet (link below) it is a Read and Write register so i guess there shouldnt be an issue with what i am trying to do. Has anyone come across anything similar to this or have any suggestions on why i might not be able to write to the AD7746. I have also tried other writeable registers with the same code and get the same issue.
Any help or advice would be greatly appreciated!