Troubleshooting Teensy 3.1 / MCP4725

Status
Not open for further replies.

jakorten

Well-known member
I am trying to get a MCP4725 working (MCP4725A1T) but no luck so far with my Teensy 3.1 I need to DAC's so the built-in one is not enough :)

My print used the DAC_MCP4725SOT Eagle part from SFE so it should be connected well. I use SCL0 / SDA0.

I actually also tried the "Teensy3.0/3.1 I2C Scanner" from Brian (i2c_t3) to no avail.

This is my code:
Code:
#include <Wire.h>
#include <Adafruit_MCP4725.h>

Adafruit_MCP4725 dac;

void setup(void) {
  delay(1000);
  Serial2.begin(9600);
  delay(1000);
  Serial2.println("Hello!");
  delay(1000);

  // For Adafruit MCP4725A1 the address is 0x62 (default) or 0x63 (ADDR pin tied to VCC)
  // For MCP4725A0 the address is 0x60 or 0x61
  // For MCP4725A2 the address is 0x64 or 0x65
  dac.begin(0x62);
    
  Serial.println("Generating a Square wave");
}

void loop(void) {
    uint32_t counter;
    // Run through the full 12-bit scale for a triangle wave
    dac.setVoltage(4095, false);
    delay(1000);
    dac.setVoltage(0, false);
    delay(1000);
    
}

I have connected an LED between the DAC out and GND to see results.

SDA is connected to SDA0 / SCL is connected to SCL0
 
Last edited:
Actually I already found a beginning:
Code:
// --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    [url]http://www.gammon.com.au/forum/?id=10896[/url]
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// 
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

//#include <Wire.h>
#include <i2c_t3.h>
#ifdef I2C_DEBUG
    #include <rbuf.h> // linker fix
#endif

void setup()
{
  Wire.begin(I2C_MASTER, 0x00, I2C_PINS_18_19, I2C_PULLUP_INT, I2C_RATE_400);
  delay(1000);
  Serial.begin(9600);
  Serial.println("\nI2C Scanner");

}


void loop()
{
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++ ) 
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16) 
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");

      nDevices++;
    }
    else if (error==4) 
    {
      Serial.print("Unknow error at address 0x");
      if (address<16) 
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(5000);           // wait 5 seconds for next scan
}

This gives me back: "I2C device found at address 0x63 !" so that is a good sign ;)
0x62 should have been 0x63 at least!
 
Last edited:
There were several problems why it didn't work for me:
a. the scanner sketch from i2c_t3 uses I2C_PULLUP_EXT and since I have one very close chip I don't use external pull-ups, this made me see my chip on address 0x63 as it should have been
b. the Adafruit_MCP4725 code has this code: TWBR = ((F_CPU / 400000L) - 16) / 2; that doesn't work with Teensy (see other topics on the forum about this)
c. i2c_t3 should be used in the Adafruit_MCP4725 to make it fit for the Teensy
d. then Wire.begin(addr) should be replaced with Wire.begin(I2C_MASTER, addr, I2C_PINS_18_19, I2C_PULLUP_INT, I2C_RATE_400);
I2C_PULLUP_INT could of course in other cases be I2C_PULLUP_EXT etc. and the code could even be more adaptive, but that is why I created a Teensy_MCP4725 as a variant for the Adafruit_MCP4725 library.

And there was an address issue that I initially overlooked in my initial code (0x62 -> 0x63).
 
Status
Not open for further replies.
Back
Top