-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Description
Hi. Thank you for the great effort put into developing this set of libraries.
I have encountered a serious issue with the I2Cdev.h
library where the values reported from the registers of an AD7746 chip are wrong.
I have implemented a read_register
method, similar to the already existing write_register
method from the AD7746
library.
uint8_t AD7746::read_register(uint8_t addr)
{
uint8_t data;
I2Cdev::readByte(_devAddr, addr, &data);
return data;
}
where data
holds the 8-bit value from the requested register.
The issue is that the retrieved data is wrong. If I change the implementation to a slightly more barebones approach, I get the right values:
uint8_t AD7746::read_register(uint8_t addr)
{
_i2c->beginTransmission(_devAddr);
_i2c->write(addr);
_i2c->endTransmission(false);
_i2c->requestFrom(_devAddr, (uint8_t)1);
return _i2c->read();
}
Please note that I made some additional modifications to the AD7746
library, where I pass a pointer to my Wire
port (since the ESP32 board has multiple I2Cs).
Here is a result of the mistaken data and the correct one. Here I merged both methods into one to retrieve the Chip ID from my AD7746, however, the implementation using I2Cdev
fails every time reporting either 0x02
or 0x07
every time.

Pay attention to the correct Chip ID 0x51
retrieved by my implementation (confirmed through the AD7746 Eval Board GUI App) while the one using I2Clib.h
reports 0x07
. In this case, I made a code that reads all registers from 0x00
to 0x13
hence why there are so many lines.
Similarly, retrieving the capacitance reports completely wrong values. Since the original method getCapacitance
uses the I2Clib.h
header, I decided to make some modifications and work on my implementation that avoids using it.
uint32_t AD7746::getRawCapacitance()
{
uint32_t capacitance = 0;
uint8_t _cap_buffer[3] = {0, 0, 0};
// I2Cdev::readBytes(_devAddr, AD7746_RA_CAP_DATA_H, 3, _cap_buffer); // --> this fails every time
// Using my implementation
_cap_buffer[0] = this->read_register(AD7746_RA_CAP_DATA_H);
_cap_buffer[1] = this->read_register(AD7746_RA_CAP_DATA_H + 1);
_cap_buffer[2] = this->read_register(AD7746_RA_CAP_DATA_H + 2);
capacitance = ((uint32_t)_cap_buffer[0] << 16) | ((uint32_t)_cap_buffer[1] << 8) | (uint32_t)_cap_buffer[2];
if (_debug)
{
sprintf(_printBuffer, "C [hex] = 0x%X\n", capacitance);
_debugPort->print(_printBuffer);
}
return capacitance;
}
Once again, I get the right values by NOT using the library but rather my proposed solution
