0

I have an Arduino Mega AT2560 and need to have real DAC. I purchased the Sparkfun 12 bit DAC, however I don't think it is working properly.

I am using the Arduino wire library to communicate with the DAC. When I write 0, I am expecting to see 0v from the DAC's OUT pin. However, I see some seemingly random constant voltage. In reverse, when I write 4095 to the DAC I see the same voltage as when I write 0. I expected to see 5v.

  1. Can someone verify that I hooked it up correctly?
  2. Can someone verify the code I am using?

12 Bit DAC with Arduino ATMega 2560

#include <stdint.h>
#include <stdio.h>
#include <Wire.h>

#define MCP4725_ADDR 0x60 // [0000 0110]
/*
* 12 Bit DAC MCP4725 gives a range of 4096 possible values.
* 
*/
void setup() {
  Wire.begin();
  Serial.begin(9600);
}

void loop() {
  Wire.beginTransmission(MCP4725_ADDR);
  Wire.write(64);            // cmd to update the DAC [0100 0000]
  Wire.write(4095 >> 4);        // the 8 most significant bits...
  Wire.write((4095 & 15) << 4); // the 4 least significant bits...
  Wire.endTransmission();
}

migrated from electronics.stackexchange.com Oct 9 '15 at 14:23

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

  • Full scale should be 4095, not 4096. In hex, 4095 id 0x0FFF, and 4096 is 0x1000. You do have a range of 4096 possible values, from 0 to 4095. – Peter Bennett Oct 8 '15 at 22:05
  • I updated the code and tried with 4095 and still am not getting 5v. – Michael Vo Oct 8 '15 at 23:11
  • Why are you left-shifting in the third "write" line? Does your communication protocol communicate in 4-bit chunks or 8-bit chunks? – The Photon Oct 8 '15 at 23:21
  • I am using basically the same operations from the Sparkfun example: learn.sparkfun.com/tutorials/… – Michael Vo Oct 8 '15 at 23:31
  • The system uses 8 bit bytes of data. – Michael Vo Oct 9 '15 at 1:01
1
  1. you want to make sure that there are pull-ups on the SCL/SDA lines;
  2. you want to make sure that the address is correct. some routines use 7-bit notation for that, and others use 8-bit notation for that. end of the day, you want the transmission to be 0xc0 | (A2:A1:A0:R/W). so check the write.write() and see what it expects. I suspect that it expects 0xCx, rather than 0x6x.

having said that, here is your code running on an uno, with the dac configured as per sparkfun spec.

enter image description here

so I think it is fair to say that the code is ok but something happened on your end that prevented it from working.

0

Sorry I'm late -- I realize this question was asked 8 months ago, but it doesn't look like you fixed it, and I figure others can always benefit (or you might even, if you still want to try).

Your code looks correct (I compared it to the Sparkfun example, and also to the datasheet for the MPC4725).

However, it does look like you're using the wrong address for the part. (The actual value for the address is not given in the Sparkfun example -- at least, I couldn't find it).

Your line:

#define MCP4725_ADDR 0x60 // [0000 0110]

is wrong in two places:

1) 0x60 is 0110 0000, not 0000 0110

2) According to the datasheet (section 7.2), the address should begin with the device code %1100, and then the address gets appended. So assuming an address of A2 = 0, A1 = 0, and A0 = 0 (default), the value for MCP4725_ADDR looks like it should be 0xC0 or %1100 000x. If you soldered the address line to Vcc instead of ground, the address should be 0xC2 or %1100 001x.

The x in the address line represents the read/write bit. If you're trying to command the DAC, it should not be asserted, so the addresses above are correct. If you're trying to read the current value, it should be asserted, which makes your address 0xC1 or 0xC3.

If you have the address wrong, even though the rest is correct, the part will ignore it, so that's probably the issue you're seeing.

Hope this helps someone!

  • SparkFun's example at learn.sparkfun.com/tutorials/… says: #define MCP4725_ADDR 0x60 //For devices with A0 pulled HIGH, use 0x61 and the same page says "we’ve broken out the address selection pin (A0) to a jumper pad. By default, this pin is pulled LOW to GND" so that indicates 0x60 is correct. – per1234 Dec 21 '16 at 12:19
  • Remember that the (usual) I2C address is composed by a 7 bit identifier and one bit which indicates whether the master is asking for a write or a read operation. The 7-bit address is 0x60; the byte sent on the bus will be 0xC0 or 0xC1, depending on the operation. Arduino's function expects the 7-bit address and the datasheet provides the byte to be transmitted.. – frarugi87 Jan 20 '17 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy