MCP4728 on GIGA via SCL2/SDA2 (can't get to work)

I have a GIGA R1 and Adafruit MCP4728 breakout board along with their library and example code. Connection via the base I2C pins (20/21) on the GIGA works fine, but only if the MCP4728 base address of 0x64 is used in mcp.begin(). We need this to work from pins D8/D9 (on GIGA, SCL2/SDA2) but cannot get anywhere after many hours trying. We tried an I2C scanner posted in this forum section by KurtE (Giga R1 Wire library issues) and this finds an MCP4728 not on SCL2/SDA2, but on SCL1/SDA1, but also shows its address at 0x60 rather than 0x64 as required by the Adafruit. I added some comments in the code,, which is here:`

/* 
Basic use of Arduino library for MicroChip MCP4728 I2C D/A converter.
For discussion and feedback, please go to http://arduino.cc/forum/index.php/topic,51842.0.html

Modified to add incremental test values in Loop(), and various attempts to get it working using
pins D8/D9 on GIGA, which are supposedly SDA2 and SCL2, requiring external pullups which are 
present on custom shield, as well as the Adafruit breakout. See comments below...
*/

#include <Adafruit_MCP4728.h>
#include <Wire.h>

#define LDACpin 6
Adafruit_MCP4728 mcp;   // Instantiate mcp4728 object

int iflag;
unsigned int idac0, idac1, idac2, idac3;    // For Loop() sequencing

void setup()
{
  Serial.begin(115200);   // Initialize serial interface for prints
  delay(100);
  
/* Works on default I2C pins (20/21 on GIGA) using Adafruit breakout board, which has MCP4728 at
   address 0x64 (or at least code only works using that acdress). Running I2C scanner posted on forum by KurtE:
   https://forum.arduino.cc/t/giga-r1-wire-library-issues/1234383
   This produces:
   
   Scanning Wire...
   No I2C devices found

   Scanning Wire1...
   Device found at address 0x60  (MPL3115,MCP4725,MCP4728,TEA5767,Si%351)

   Scanning  Wire2...
   Device found at address 0x64 (AtlasEzoEC, ADAU1966)

   This is somehow seeing the MCP4728 at 0x60, but this (modified) Adafruit example code only runs
   properly using address 0x64 (using SCA/SDL pins 20/21 on GIGA).  I modified the code below using
   all 4 combinations (Wire1.begin with either 0x60 or 0x64 in mcp_begin, or Wire2.begin with both
   addresses) with the MCP4728 breakout board attached to D8/DD9, but none of these combinations work.
   Very puzzling why the I2C scanner sees the MCP4728 at 0x60, while the Adafruit code only works at 0x64.
   Have not changed the default MCP4728 address here (done at Adafruit?).


*/

//  Tried adding below to use SDA2 (D9) and SCL2 (D8) on GIGA but no luck. Is problem in Adafruit library?
// Start I2C on SDA1/SCL1 
//  Wire1.begin();
// Start I2C on SDA2/SCL2 
//  Wire2.begin();

// Try to initialize MCP4728 at 0x60 (default) or 0x64
//  if (!mcp.begin(0x64)) {
  if (!mcp.begin(0x60)) {
    Serial.println("Failed to find MCP4728 chip");
    while (1) {
      delay(10);
    }
  }
  Serial.println("MCP4728 Found at 0x60");
//  Serial.println("MCP4728 Found at 0x64");

  pinMode(LDACpin, OUTPUT); 
  digitalWrite(LDACpin, LOW);     // Also tried hard grounding this pin ... no change in results

// Set outputs to 0V to intialize
  mcp.setChannelValue(MCP4728_CHANNEL_A, 0);
  mcp.setChannelValue(MCP4728_CHANNEL_B, 0);
  mcp.setChannelValue(MCP4728_CHANNEL_C, 0);
  mcp.setChannelValue(MCP4728_CHANNEL_D, 0);

// Set starting values for Loop() sequences
  idac0 = 0;
  idac1 = 200;
  idac2 = 400;
  idac3 = 600;

//  iflag = 0;
}

/******************************************************************************************/
void loop()
{
//  Basic analog writing to DAC

  idac0 = idac0+ 200;
  if(idac0 > 4095)
     idac0 = 0;

  idac1 = idac1+ 200;
  if(idac1 > 4095)
     idac1 = 200;

  idac2 = idac2+ 200;
  if(idac2 > 4095)
     idac2 = 400;

  idac3 = idac3+ 200;
  if(idac3 > 4095)
     idac3 = 600;

  mcp.setChannelValue(MCP4728_CHANNEL_A, idac0);
  delay(10);
  mcp.setChannelValue(MCP4728_CHANNEL_B, idac1);
  delay(10);
  mcp.setChannelValue(MCP4728_CHANNEL_C, idac2);
  delay(10);
  mcp.setChannelValue(MCP4728_CHANNEL_D, idac3);

  delay(3000);

}      // End of Loop routine`

Any ideas out there for why this won't work as attempted above? Could the Adafruit library not support alternative I2C pins? We also tried another MCP4728 library but could not get that compile due to numerous errors, so stuck with the Adafruit library as it does work as long as we use GIGA pins 20/21 for I2C.

Hi, try changing

if (!mcp.begin(0x60)) {

to

if (!mcp.begin(0x60, &Wire2)) {
1 Like

Thanks steve9 ... that worked! I had to keep the address at 0x64 instead of 0x60 for it to work (compatible with the Arduino test code when connected to SDA/SCL at pins 20/21), which makes the I2C scanner results still a puzzle. But it works which is all that counts. Thanks for the quick reply!

No probs. The address is a puzzle. 0x60 is adafruit default, and that's what KurtE's scanner found (numbering is an issue on this board with mbed to arduino). FYI, always inspect the .h of any lib you include. Sometimes hidden gems, other times a fix for your prob

p.s. quick read of the datasheet for the chip. The address is user programmable - which is cool. So it acknowledged the scan on 0x60 (so you could change it) but its current setting is 0x64 - nice