View previous topic :: View next topic |
Author |
Message |
wewa
Joined: 02 Jul 2008 Posts: 27
|
Problem with I2C between PIC18F and MAX5820 (DAC) |
Posted: Sat Feb 14, 2009 7:59 am |
|
|
Hi!
I'm trying to control a MAX5820 DAC with a PIC18F4525. My problem is this doesn't work.
I've monitored SDA and SCL and it seems that the connection is ok, because MAX5820 sends the ACK bit (pulling SDA low while 9th SCL clock cycle).
Maybe something in my code is wrong. I'm very unsure about my set_DAC procedure. (And without writing something to the DAC I can't really test my get_DAC function. Maybe you can tell me whats wrong in my code.
This are my functions: Code: | //using CCS-compiler with MPLAB
#define DAC 0x70
void set_DAC(char dac_a, char dac_b) { //set DAC A and DAC B of MAX5820
i2c_start();
i2c_write(DAC|0x00);
i2c_write(0x00|dac_a>>4);
i2c_write(dac_a<<4);
i2c_stop();
i2c_start();
i2c_write(DAC|0x00);
i2c_write(0x10|dac_b>>4);
i2c_write(dac_b<<4);
i2c_stop();
}
char get_DAC(int1 select) { //read DAC A or DAC B data from MAX5820
char tmp=0x00;
i2c_start();
i2c_write(DAC|0x00);
if(select) i2c_write(0xF1); //read DAC A
else i2c_write(0xF2); //read DAC B
i2c_start();
i2c_write(DAC|0x01);
tmp=i2c_read()<<4;
tmp=tmp|i2c_read()>>4;
i2c_stop();
return tmp;
} |
And here's the datasheet: http://www.farnell.com/datasheets/112025.pdf
Thanks for any help. |
|
 |
Kenny
Joined: 07 Sep 2003 Posts: 173 Location: Australia
|
|
Posted: Mon Feb 16, 2009 4:43 pm |
|
|
I haven't used this chip, but here are a few things to check.
This implies the MAX5820L part with the Vadd pin connected to GND.
Confirm that the reference is connected.
Guess it is possible that the DACs have been inadvertently powered down.
May need to write the powerup sequence first. |
|
 |
wewa
Joined: 02 Jul 2008 Posts: 27
|
|
Posted: Tue Feb 17, 2009 9:04 am |
|
|
Thanks for answer.
Yes the Vadd-pin is connected to ground.
Tomorrow I'll try the power-up command and report if it helps.
wewa |
|
 |
wewa
Joined: 02 Jul 2008 Posts: 27
|
|
Posted: Wed Feb 18, 2009 8:17 am |
|
|
Thanks!
You were right, the DAC was in power-down mode.
After setting in power-up mode the device works. |
|
 |
|