On Wed, 24 Sep 2008 08:20:12 -0700 (PDT), you wrote: >I've written a few C functions for dealing with external page write >eeprom. I have these functions: > >WriteEepFirstByte(address, data) // sets up address, sends data, >increments static address counter, leaves /CS low > >WriteEepNextByte(data) // sends data, increments static address counter, >does page write if incremented to new page, leaves /CS low > >WriteEepLastByte(data) // sends data, does page write, releases /CS > >WriteEepOnlyByte(address, data) // writes the specified byte to the >specified address. > As multiple writes are often from sequential memory, a routine that reads/writes a number of consecutive bytes will often cover most eventualities. Where you have a block of things like parameters that need reading seperately, this can be handled neatly by either using a union of an array and individual chars/ints/whatever, or simply #defining the individual parameters as array elements. e.g. char params[16]; #define param1 params[1] #define param2 params[2] Another thing that can make things neater is have procedures to read/write bytes to/from memory, splitting page writes as required so the caller doesn't need to worry about it. Then have macros that generate from the size of variable used. below is an example in IAR C for ARM, but the same principle applies for other targets. #define writeeeprom(adr,targ) dowriteeeprom(adr,sizeof(targ),(char*)&targ) void dowriteeeprom(Int32U adr,Int32U nbytes,char *dest) { Int32U i,lump; do { kickwatchdog(); lump=(nbytes<=eepagesize)?nbytes:eepagesize; i=eepagesize-(adr & (eepagesize-1)); // page size - offset within page - max we can write in 1 go if (lump>i) lump=i; // chop length to page boundary while(iistart(0xa2)) {I2C0CONCLR=8;} //wait not busy sendiic(adr>>8); sendiic(adr); adr+=lump; nbytes-=lump; do sendiic(*dest++); while(--lump); iistop(); } while (nbytes); } This would be called like writeeprom(0,param1); and the correct size of param1 would automatically be fed to the write routine. -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist