From: Wolfram Liebchen Subject: Re: Code for MAX 186 serial A/D >>> Has anyone written code for the MAXIM 186 8-channel serial A/D >> >> (...) What you really need is just >>some good I2C routines to talk to the Maxim chips. If you are >>interested I can share my code with you, but unfortunately it was > Why do you need I2C routines to communicate with the Maxim chips? They > use SPI or Microwire (however you call it) and not I2C ?!? Oops! My apologies. You are absolutely correct. It has been about 2 years since I've finished this project, and since I also used some I2C chips on the same project I somehow mistakingly thought that the Maxim chips were I2C based. Anyway, since a few people asked me for the routines, here is the one I used to talk to the MAX 186 and as Wofram pointed out, it is not I2C: : ) ////////////////////////////////////////////////////////////////////// // READ AD // Clocks 10 bits A/D value in from one of eight // channels selected by the paramenter 'chan'. It return the digital // value as an integer to the calling procedure. Mostly called from / / the Main routine. ////////////////////////////////////////////////////////////////////// / int Read_AD( byte chan ) { int readval=0; char cnt; SCK = FALSE; // Just make sure that SCK is LOW at the start SHDN = 1; // Power the A/D up CS0 = FALSE; // select ADC // Indicate which channel to read for (cnt=0; cnt<8; cnt++) // Clock the control byte into DIN { DIN = chan & 0x80; // pass only MSB SCK = FALSE; // Toggle SCK SCK = TRUE; chan <<= 1; // Rotate one position to the left } SCK = FALSE; // Toggle SCK between control and read SCK = TRUE; //// read ad value for (cnt = 0; cnt < 10; cnt++) // Clock the control byte intoDIN { readval <<= 1; SCK = FALSE; // Toggle SCK high SCK = TRUE; // Toggle SCK low DOUT = TRUE; // Pull DOUT high if (DOUT) readval++; } SCK=FALSE; // leave SCK lo at end CS0 = TRUE; // unselect ADC SHDN = 0; // Power down to conserve power. return readval; }