PCF8591T I2C 8-bit A/D and D/A

This is an I2C 8-bit A/D and D/A converter with changeable address and can have up to 8 on a single bus. The Base Address of the devices is 48h (i.e. all address pins are set to 0v)

Hardware

Photo A To D Diagram D To A Diagram
source:/PCF8591T/doc/PCF8591T.jpg source:/PCF8591T/doc/PCF8591T_AtoD.JPG source:/PCF8591T/doc/PCF8591T_DtoA.JPG

EXT & OSC Pin setup

EXT and the OSC are both tied to GND, this switches off the internal oscillator and reduces errors in the conversion.

Digital to Analog

This is using a coded data example and reads in the result using the AnalogIn on the mbed itself

Ain 0-3 By setting these all to 0v I have eliminated these as possible error makers for coding, me just being me, I never like floating pins.

Source Code Binary
#include "mbed.h"

I2C i2c (9, 10);
Serial pc (USBTX,USBRX);
AnalogIn ain (20);
const int addr = 0x48; // Base Address Of PCF8591T

int main() {
char cmd[2];
cmd[0] = 0x40; //Command Address Setup
cmd[1] = 0xFF; //Data To Convert

i2c.write(addr, cmd, 2); //Command Address Is Then Sent With The Data
wait(0.2);
pc.printf("result %.2f V ",ain * 3.3); //Print Voltage to the Screen

}
i2cDtoA.bin

Analog to digital

For this I have attached a pot to the Ain0 Pin and tied the rest to 0v. I have also set up the command register to just read in from that value.
Coincidentally it's the same command address as the Digital to Analog.

Source Code Binary
#include "mbed.h"

I2C i2c (9, 10);
Serial pc (USBTX,USBRX);
const int addr = 0x48; //// Base Address Of PCF8591T
char cmd[1];
char i;
int main() {
    cmd[0] = 0x40; //Command Address Setup
    i2c.write(addr, cmd ,1); //Write Command Address

while(1) {
    i2c.read(addr, cmd, 1); //Read The Data Block

    i = cmd[0];
    pc.printf(" Digital value = %d\n ", i); //Print Out Digital Value To The Screen

    }
}
i2cDtoA.bin

Resources

Datasheet