Hi Ken, There is still not output from the DAC. I am suspecting that I may initial the TRISC incorrectly. What do you think might be the problem? I have tied the Vref (pin8) to high, just wanna see whether is ther any voltage in the output. I have double check my hardware connection and it seem alright. Please advise me? Thanks, Nicholas #include #include //function prototype void MAX517(unsigned char data_DAC, unsigned char DAC_Address); void main(void){ char data_DAC; char DAC_Address = 0x58; //init condition TRISC = 0X1A; //Set SDA & SCL as 1. Activate I2C port OpenI2C(MASTER, SLEW_ON); //Initialize I2C module SSPADD = 9; //400KHz Baud clock (9) @16MHz while(1){ //Start condition data_DAC = 0x7F; MAX517(data_DAC, DAC_Address); //Write data to I2C DAC }//end of while }//end of main //DAC function void MAX517(unsigned char data_DAC, unsigned char DAC_Address) { DAC_Address = (DAC_Address & 0xFE); // Coerce address byte to WRITE mode StartI2C(); // Start condition WriteI2C(DAC_Address); // Address byte of DAC WriteI2C(0x00); // Command byte WriteI2C(data_DAC); // Output Data StopI2C(); // Stop condition } ----- Original Message ----- From: "Ken Pergola" To: Sent: Friday, March 19, 2004 1:19 AM Subject: Re: [PIC]:I2C DAC test > Nicholas wrote: > > > Sorry for not explaining that. > > By adding the 'I2C_Address' parameter to your MAX517 function, I made it > more universal versus the way you coded it. Your code was not bad at all, > I'm just showing you a different perspective, that's all. > > In other words, you had hard-coded the I2C address so that only a MAX517 > with a slave device address of 0x2C would work. > By having your MAX517 function accept an 'I2C_Address' argument, I'm showing > you how you can accommodate up to 4 MAX517 devices on the I2C bus with one > function if you ever need future expansion. > > Be careful Nicholas, you did not use my exact example that I posted > yesterday. Somehow you changed my code. You need to add my original code > back in. > > My original reference was: > > I2C_Address &= 0xFE; // Coerce address byte to WRITE mode > > > The reference to 'I2C_Address &= 0xFE;' should have been written more > clearly as: > > I2C_Address = ( I2C_Address & 0xFE ); > > Both do the same thing -- just short-hand versus long-hand. > > The '&' is the bitwise AND operator. What this is doing is forcing your R/W > bit (bit 0) of your I2C address to be 0 without affecting the other 7 bits. > In this case, it is just defensive programming since you could have passed > in 0x59 (R/W bit = 1 = read) (correct 7-bit device address but incorrect > 8-bit I2C address). > > Nicholas, I think you are doing great so far -- keep up the good work and do > not give up. You'll be posting soon sharing your success with us. > > > Best regards, > > Ken Pergola > > P.S. Don't forget to make that change: I2C_Address = ( I2C_Address & 0xFE ); > > -- > http://www.piclist.com hint: The list server can filter out subtopics > (like ads or off topics) for you. See http://www.piclist.com/#topics > -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.