Hi everyone, I have trouble with ADG2128. My objective is 4-wire BIA measuring in 'EVAL-CN0565-ARDZ' using Arduino Wemos D1. Specifically, after configuring AD5940 depending on this code:
(github.com/.../BodyImpedance.c)
It worked, there was a sine waveform at CE0 (capacitor C1). But I tried many ways to configure ADG2128 but it didn't work. At first, it cannot communicate to ADG2128 (I2C). I reconfigured AD5940's GPIO, and then it can (I can read the value 0x70 and 0x71 of the two ADG2128. But up to now, there has been no signal or waveform at CN0565's pins (in the picture). The full I2C Arduino code is attached below (The code for Ad5940 is in the link).
Thank you very much. I'm really grateful for that.

struct adg2128_pinmap {
uint8_t chip_addr; // I2C address
uint8_t selector; // Mux config (X input)
};
struct adg2128_pinmap board_map[ADG2128_MUX_SIZE] = {
{0x71, 0x80}, // Electrode 0, I2C addr = 0x71, X0
{0x71, 0x88}, // Electrode 1, I2C addr = 0x71, X1
{0x71, 0x90}, // Electrode 2, I2C addr = 0x71, X2
{0x71, 0x98}, // Electrode 3, I2C addr = 0x71, X3
{0x71, 0xA0}, // Electrode 4, I2C addr = 0x71, X4
{0x71, 0xA8}, // Electrode 5, I2C addr = 0x71, X5
{0x71, 0xC0}, // Electrode 6, I2C addr = 0x71, X6
{0x71, 0xC8}, // Electrode 7, I2C addr = 0x71, X7
{0x71, 0xD0}, //Electrode x, I2C addr = 0x71, Mux Config (X8 to Yn)
{0x71, 0xD8}, //Electrode x, I2C addr = 0x71, Mux Config (X9 to Yn)
{0x71, 0xE0}, //Electrode x, I2C addr = 0x71, Mux Config (X10 to Yn)
{0x71, 0xE8}, //Electrode x, I2C addr = 0x71, Mux Config (X11 to Yn)
{0x70, 0x80}, // Electrode 8, I2C addr = 0x70, X0
{0x70, 0x88}, // Electrode 9, I2C addr = 0x70, X1
{0x70, 0x90}, // Electrode 10, I2C addr = 0x70, X2
{0x70, 0x98}, // Electrode 11, I2C addr = 0x70, X3
{0x70, 0xA0}, // Electrode 12, I2C addr = 0x70, X4
{0x70, 0xA8}, // Electrode 13, I2C addr = 0x70, X5
{0x70, 0xC0}, // Electrode 14, I2C addr = 0x70, X6
{0x70, 0xC8}, // Electrode 15, I2C addr = 0x70, X7
{0x70, 0xD0}, //Electrode x, I2C addr = 0x70, Mux Config (X8 to Yn)
{0x70, 0xD8}, //Electrode x, I2C addr = 0x70, Mux Config (X9 to Yn)
{0x70, 0xE0}, //Electrode x, I2C addr = 0x70, Mux Config (X10 to Yn)
{0x70, 0xE8}, //Electrode x, I2C addr = 0x70, Mux Config (X11 to Yn)
};
// Electrode Combo Structure (4 electrodes for Y0-Y3)
struct electrode_combo {
uint16_t y0;
uint16_t y1;
uint16_t y2;
uint16_t y3;
};
void setMuxSwitch(struct electrode_combo sw, uint16_t nElCount) {
uint8_t i2c_addr;
uint8_t muxData[2] = {0, 0x00}; // Latch bit 0x00 (immediate update)
uint16_t *Y = (uint16_t *)&sw; // Access sw as array
uint16_t curr_el;
uint8_t i;
// Compute electrode factor
uint16_t el_factor = (uint16_t)ADG2128_MUX_SIZE / nElCount;
if (el_factor != 0 && ((el_factor & (el_factor - 1)) == 0)) {
// Configure switches for Y0-Y3
for (i = 0; i < 4; i++) {
if ((*(Y + i)) < ADG2128_MUX_SIZE) {
curr_el = (*(Y + i)) * el_factor;
i2c_addr = board_map[curr_el].chip_addr;
muxData[0] = board_map[curr_el].selector + (i << 1); // Adjust Y output
Wire.beginTransmission(i2c_addr);
Wire.write(muxData[0]);
Wire.write(muxData[1]);
int error = Wire.endTransmission();
if (error == 0) {
Serial.print("ADG2128 0x"); Serial.print(i2c_addr, HEX);
Serial.print(": Electrode "); Serial.print(curr_el);
Serial.print(" to Y"); Serial.println(i);
} else {
Serial.print("I2C Error for 0x"); Serial.print(i2c_addr, HEX);
Serial.print(": "); Serial.println(error);
}
}
}
delayMicroseconds(1); // Replace no_os_udelay
}
}
void setup()[ // it should be '//'
SPI.begin();
Wire.begin();
Wire.setClock(100000);
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(CS_PIN, OUTPUT);
Serial.println("");
struct electrode_combo sw = {0, 20, 15, 7};
setMuxSwitch(sw, 24); // Use all 16 electrodes
digitalWrite(CS_PIN, HIGH);
Serial.println("");
AD5940_Main();
]

