On Fri, 2 Aug 2002 10:14:11 +1200 Jinx writes: > Does anyone have simple, repeat simple, code to show > setup and operation of said module to read / write bytes > to an EEPROM ? Examples I've found so far are convoluted > over-blown state machines for multi-device systems that are > way OTT for my needs. So much use of collision and error > routines I found it hard to pick out the basics. Normally I'd > nut it out myself but I've read that some examples (MC in > particular) aren't worth the screen they're printed on, so I'd > rather not waste time on published code that doesn't work > Here's some stuff in Microchip C to talk to a CAT24W64. void SetPaddr(unsigned int addr){ // Sets address of next eeprom read or write OpenI2C(MASTER, SLEW_ON); // Initialize the I2C as a master SSPADD=22; // 400 kbps with 40 MHz clock IdleI2C(); // Wait for i2c to be ready StartI2C(); // Send a start IdleI2C(); // Wait for i2c to be ready WriteI2C(0xa0); // Send slave address (0xa0) with rw bit low (write) IdleI2C(); // Wait for i2c to be ready WriteI2C(addr>>8); // Send the high half of the address address IdleI2C(); // Wait for i2c to be ready WriteI2C(0xff & addr); // Send the low half of the address IdleI2C(); StopI2C(); // Send a stop IdleI2C(); // Wait for i2c to be ready CloseI2C(); // Done with I2C } unsigned char ReadPeep(void){ // Read a byte from eeprom chip at "current address" unsigned char data; // Keep our data while we close the I2C OpenI2C(MASTER, SLEW_ON); // Initialize the I2C as a master SSPADD=22; // 400 kbps with 40 MHz clock IdleI2C(); // Wait for i2c to be ready StartI2C(); // Send a start IdleI2C(); // Wait for i2c to be ready WriteI2C(0xa1); // Send slave address with r/-w high indicating we're reading IdleI2C(); // Wait for i2c to be ready data=ReadI2C(); // Get the data IdleI2C(); // Wait for i2c to be ready StopI2C(); // Send an I2C stop IdleI2C(); // Wait for i2c to be ready CloseI2C(); // Done with I2C return(data); // Exit with the data we got } void WritePeep(unsigned int addr, unsigned char data){ // Write a byte to the eeprom OpenI2C(MASTER, SLEW_ON); // Initialize the I2C as a master SSPADD=22; // 400 kbps with 40 MHz clock IdleI2C(); // Wait for i2c to be ready StartI2C(); // Send a start IdleI2C(); // Wait for i2c to be ready WriteI2C(0xa0); // Send the slave address with the r/-w low indicating we're writing an address IdleI2C(); // Wait for i2c to be ready WriteI2C(0xff & (addr>>8)); // Send the high half of the address address IdleI2C(); // Wait for i2c to be ready WriteI2C(0xff & addr); // Send the low half of the address IdleI2C(); // Wait for i2c to be ready WriteI2C(data); // Send the data IdleI2C(); // Wait for i2c to be ready StopI2C(); // Send an I2C stop IdleI2C(); // Wait for i2c to be ready CloseI2C(); // Done with I2C } Good luck! Harold FCC Rules Online at http://hallikainen.com/FccRules Lighting control for theatre and television at http://www.dovesystems.com Reach broadcasters, engineers, manufacturers, compliance labs, and attorneys. Advertise at http://www.hallikainen.com/FccRules/ . ________________________________________________________________ GET INTERNET ACCESS FROM JUNO! Juno offers FREE or PREMIUM Internet access for less! Join Juno today! For your FREE software, visit: http://dl.www.juno.com/get/web/. -- 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