12 bit dac i2c help

Hello everyone,
I am trying to communicate to this over i2c:

I am using an atmega328. I have an uno board that i plug the chip into to program, then i run it on a seperate breadboard. The atmega and dac both run on the same regulated 3.3v
I am trying to acheive i2c communication.

I have two problems.

  1. I can’t figure out the address. The datasheet says the device code is 1100 and A2 and A1 are 00, and A0 is dependent on its state. this means the adress should either be 60 or 61.
    2.Secondly, I cant for the life of me even send a value over. I tried to use every adress (60, 61, 62, or 63).

Here is where it tells me where the address is 62 or 63 with A0 pulled high.

by the way i do have 2 of them connected to the arduino, one has A0 pulled high, does that mean i should pull the other to ground??

hopefully I didn’t leave anything out.

#include <Wire.h>
void setup()
{
  Wire.begin();  
}

void loop()
{
  
  Wire.beginTransmission(62);
  Wire.write(0);
  Wire.endTransmission();
  
  Wire.beginTransmission(63);
  Wire.write(0);
  Wire.endTransmission();
}

here is the code that i am using. It is crude just because it is an example.

any help is appreciated!

I'm assuming you are using the Adafruit breakout board, not a standalone MCP4725.

by the way i do have 2 of them connected to the arduino, one has A0 pulled high, does that mean i should pull the other to ground??

According to the Adafruit website, no, because if A0 is left floating, it is pulled low on the breakout board.

Run an I2C scanner program on your Arduino, like this one: http://forum.arduino.cc/index.php?topic=197360.0

Run it with one breakout board connected at a time and see if it is recognised by the scanner. Then try with both boards connected.

I think the breakout board includes pullup resistors on SDA and SCL, but I can't find a schematic at the moment.

Once you know the Arduino can "see" the DACs, then you need to work on your example code. From the datasheet, writing a value needs at least two bytes to be sent. Figure 6-1 refers. Adafruit have a library with sample programs.

here is Nick Gammon’s I2C scanner. It will verify that your device is connected to the bus and give the address. You have the pullup resistors in place, right?

#include <Wire.h>

void setup() {
  Serial.begin (115200);

  // Leonardo: wait for serial port to connect
  while (!Serial) 
    {
    }

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  
  Wire.begin();
  for (byte i = 1; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}

Yes i am using the breakout board. Okay thank you very much, that is a good idea. Do you think if it already has pullup resistors then that would be a problem?
Also, in my code I used to have it write(byte(0)); before it sent the actual data. I need to learn how to read the datasheets better cause they confuse me alot.

  1. I can't figure out the address. The datasheet says the device code is 1100 and A2 and A1 are 00, and A0 is dependent on its state. this means the adress should either be 60 or 61.

Do you mean 0b1100, 0x60, 0x61 ? I think you do.

Alright so I first tried just to upload a simple blink sketch to the atmega via arduino uno. It uploaded and worked on the uno but wont work on my breadboard. I figured this might be why the i2c does not work. The only problem is now that I don't know why it is not working on my breadboard. here is a schematic:

here is schematic, other version of it was too large to attatch.

You need to give us more information regarding how you uploaded code on the 328p.

Tell us if you used Arduino ISP and what bootloader is on the atmega ?

I see you wrote 3,3v for the mcp supply power but how do you power your 328p (you only wrote 3,3v) ?

Have you tried a simple turn on led sketch to verify your uploaded code is working ?

If you verified that you can upload sketches correctly then it´s time to scan for I2C devices (arduino only handles 7 bit of adress data, but that shouldn´t be a problem in your case). Be sure both devices have power before you use the scanner to avoid bus problems.

I program the 328 by plugging it into my arduino uno board. While it was in the uno board, I verified that the atmega worked via a simple blinking led sketch. What I do is pull out the 328 off the uno board and plug it into my circuit. Both the mcp4725 and atmega 328 are powered by a regulated 3.3v supply. I have verified that both of them are being powered up using my multimeter. The problem is when I upload code, it works fine when the 328 is in the arduino board but the 328 does not work when in my external circuit.

Sorry i don´t understand what you mean by plugging the 328p into your arduino board, the boards i use have an smd chip on it and can´t be removed that easily. Maybe show us a photo of your hardware ?

You still haven´t answered which bootloader you use for any of your chips.

If you want to know the adress you can try using the scanner in your "working circuit". Since you power your arduino with 5v then it might damage the mcp but i don´t think so (i never damaged any device, use at your own risk!).

My arduino board can accept any atmega328pu 28 pin dip chip. So all i have in my other circuit is a 28 pin retention contact so I can essentially plug the atmega into the uno or my circuit. I bought the uno board with the 328 in it and it already had the bootloader on it, so I am assuming it has the "standard" bootloader. I thought the arduino uno's bootloader was called optiboot but I could be wrong.

Yeah I thought about running the scanner on my working circuit, and yes the mcp4725 does work with 5v, but i figured it is redundant because it wont work on my circuit in the first place if you understand what I am saying.

Sorry i don´t understand what you mean by plugging the 328p into your arduino board, the boards i use have an smd chip on it and can´t be removed that easily.

Some arduino boards have the microcontroller in a socket that you can easily take the dip out of.

If you google 'arduino image' you will see thousands of photos of arduino boards, and about half of them are like that, so apparently it is not totally obscure concept.

I don't think that the 328 will run at 16Mhz on 3.3 V.

You know what, I was just looking at the datasheet and I think your right. Well now all I have to do is change either the voltage level to 5 or use its internal clock. Thanks so much!!! It was really bugging me lol.

I don't think that the 328 will run at 16Mhz on 3.3 V.

Thats why i asked about the bootloader ;)

sorry smithy, I didn't mean to overlook that. :grinning:

Alright, I am back.

I have fixed all the previous problems mentioned here. I have the atmega running on its internal 8mhz clock. It is successfuly running at 3.3v. I did a simple blink sketch and everything is working out as planned. The only thing now is programming to communicate with this digital to analog converter. I have tried my best to read this datasheet: http://www.adafruit.com/datasheets/mcp4725.pdf and understand it but I am still stuck on figuring out how to program it. The part I am stuck on is figuring out what to send using wire.write()? I can set it up with begin transmission and end, but i don't know how many bytes in between to send. what I would like to do is have the dac output a voltage in between 0-3.3v just as an example then I think once I understand the concept I will be fine.

Any help is appreciated. Thanks!

Also, I have seen the adress byte written in hex (0x__) or just regular 60 or in binary. what is the right way?

I also found out that the address is 98 and 99. 110001[A0] I had them soldered down without looking at the address, so i desoldered them and found the address on the back. Its nice that the datasheet and adafruit are both wrong.

The I2C scanner would have told you the address without all the trouble of unsoldering stuff.

If that scanner does not tell you the address you have major problems.