Communicating with Texas DAC5574 using I2C

Hi all,

I am trying to hook up the Texas Instruments DAC-5574 to a Nano using the Wire library.

I'm having some problems extracting exactly what I need to send via I2C to set the analog values on each of the 4 outputs.

In Setup I have the normal:

Wire.begin();

To set the output level on port A to 5v (0xff), I am using:

Wire.beginTransmission(0b1001100); // A0 & A1 are both tied to ground
Wire.write(byte(0b00000010)); // 
Wire.write(byte(0xff)); //
Wire.write(byte(0xff)); //
Wire.endTransmission();

The only slight problem is - it does nothing!

I am guessing I have totally misinterpreted the datasheet but I cannot find any code examples anywhere :frowning:

I'll keep trying but if anyone has any suggestions, they would be very much appreciated.

Many thanks,

James

You interpreted the datasheet correct.
I think that is how to use it.
Is there some standby or power bit that has to be set ?

Let's go back one step.
Can you run the i2c_scanner to see if the i2c bus is working and the chip is on the bus.
http://playground.arduino.cc/Main/I2cScanner

Hi,

Sorry for the delay - I left my Arduino hardware at the office over the weekend!!!

I have run the Scanner and I get this: (I've added labels for the items I am aware of)

I2C device found at address 0x27  !   LCD
I2C device found at address 0x48  !   
I2C device found at address 0x4C  !   
I2C device found at address 0x50  !   EEPROM
I2C device found at address 0x51  !   
I2C device found at address 0x60  !   TLC-59116
I2C device found at address 0x68  !   Realtime Clock
I2C device found at address 0x6B  !

I'm not sure what the other four are but I hope one of them is my DAC!

As I have A0 and A1 tied to ground, the device address should be 0x4C :slight_smile:

This is your DAC: http://www.ti.com/product/dac5574

Is it possible to remove the other I2C devices ?
Perhaps other modules have pullup resistors, resulting in a combined pullup that is too much for the DAC5574.

I have been looking at the datasheet, and I don't not fully understand it. I don't see a special power up sequence, so writing the control byte with msb and lsb should do it.
Perhaps you can ask for code examples : http://e2e.ti.com/support/data_converters/precision_data_converters/f/73.aspx

Excellent!!!!

Looks like I was sending the wrong value for the control byte!

#include <Wire.h>

// Define I2C Device Addresses
#define kDACAddress1                           0x4c        // Assumes A0 to A1 are connected to ground

// the setup routine runs once when you press reset:
void setup()
{  
    // Serial Port Initialisation
    Serial.begin(9600);              // Output to the Serial Monitor
    delay(500);                      // 

    // Initialise the I2C Library
    Wire.begin();
}

// Loop
void loop()
{
    i2c_dac5574_setvalue(kDACAddress1, 0, 0x00);
    delay(2000);
    i2c_dac5574_setvalue(kDACAddress1, 0, 0x80);
    delay(2000);
    i2c_dac5574_setvalue(kDACAddress1, 0, 0xff);
    delay(2000);
}

// i2c_dac5574_setvalue  (Sets the Value of the selected DAC Output)
//   - Parameter 1 : Device Address
//   - Parameter 2 : Output A-D   0x00 to 0x03
//   - Parameter 3 : Value        0x00 to 0xff (0 - 5v)
//  Control Byte     0    0    L1   L0   x    A1   A0   0  | Chan
//                   0    0    0    1    0    0    0    0  |  A       
//                   0    0    0    1    0    0    1    0  |  B
//                   0    0    0    1    0    1    0    0  |  C
//                   0    0    0    1    0    1    1    0  |  D
void i2c_dac5574_setvalue(byte DACAddress, int output, int value) 
{
    Wire.beginTransmission(DACAddress);
    byte ctrl = 0x00;
    ctrl |= 0x10;  // L0=1
    switch (output)
    {
        case 0: // A1=0, A0=0
            break;
        case 1: // A1=0, A0=1
            ctrl |= 0x02;
            break;
        case 2: // A1=1, A0=0
            ctrl |= 0x04;
            break;
        case 3: // A1=1, A0=1;
            ctrl |= 0x02;
            ctrl |= 0x04;
            break;
    }
    Wire.write(byte(ctrl)); // port a with next value
    Wire.write(byte(value));       // MSB
    Wire.write(byte(value));       // LSB
    Wire.endTransmission();
}

The function is working great now for all 4 outputs
Thanks a lot for the guidance...
James
:slight_smile:

Very Nice.
I hope your code will help others.