Hi,
I wrote a library for the MCP3221 (a 12-Bit ADC converter) some time ago and published it on Github.
The library works perfectly with a single MCP3221 device connected to the Arduino, but when 2 MCP3221s (with different I2C address, of course) are connected in parallel, communication with the first of the 2 devices is lost.
I've spent a lot of time trying to track down the exact issue causing this, and I think I managed to narrow things down quite significantly.
However, for the life of me, I can't figure out what the exact problem is or how to fix it.
Here a summary of what I've discovered so far in my investigation:
-
I tested the 2 devices independently and without the library (i.e. by interfacing with them directly via Wire) and verified that both are working correctly.
-
Each of the devices has a different I2C address which is pre-set in hardware (0x4D & 0x4E), so definitely no address clash.
-
I tested the 2 devices in parallel but again without the library and they work perfectly together - so I know for certain that the problem lies somewhere in the library code itself.
-
I'm almost certain the problem lies with the constructor function of the library.
The reason I say this is that when I connect just 1 of the 2 devices and run the library's built-in I2C device info sketch (included in the 'examples') , there is no problem as can be seen in the attached screen-shots below.
However, if I connect both devices in parallel and run a modified version of the said device info sketch (tweaked for checking 2 devices):
#include "MCP3221.h"
#include "utility/MCP3221InfoStr.h"
MCP3221 slave1(0x4D);
MCP3221 slave2(0x4E);
void setup() {
Serial.begin(9600);
Wire.begin();
while(!Serial);
print_current_settings(slave1);
print_current_settings(slave2);
}
void loop() {}
void print_current_settings(MCP3221 slave) {
Serial.print(F("\n\nCURRENT SETTINGS:\n"));
Serial.print(MCP3221InfoStr(slave));
Serial.print(F("\n\n"));
}
Then the feedback is that the I2C address of the first device (0x4D) has been deleted somehow (or set to '0') by the mere presence of the constructor for the second device (0x4E) - also see attached screen-shot below.
Reversing the order of construction yields the exact same results only for the other device (communication with 0x4E is good, while the I2C address of 0x4D gets erased).
So it looks like constructing a second MCP3221 instance somehow messes-up the first MCP3221, but I'm totally baffled as to why that should happen :o
The library's constructor defines each MCP3221 instance as having its own unique address, and as far as I can tell, it shouldn't be interfering with existing ones.
Help please?






