On Tue, 9 Jul 2002, Harold M Hallikainen wrote: >I'll consider making another set of functions that check idle. I'd have >to duplicate pretty much all the functions, but that might be ok. Again, >THANKS! The easy way is to copy the relevant library and then edit and insert near the top of each function something like: // define a ready-wait procedure #define I2C_WAIT if(BI2C_checkidle) { IdleI2C(); } // for example ... void SendI2C(uchar8 data) { uchar8 somelocalvar; // check for ready I2C_WAIT; // trailing semicolon is optional ... BI2C_checkidle is a flag you define in a global flags register. Beware if you use this both in ISRs and in main code. The implementation version I show here is not thread-safe. I hope that C18 inlines the IdleI2C() function or that it is short. Maybe calling functions with arity 0 is inexpensive in C18 and then you should keep the code as it is now. My change will increase code size and/or call depth. btw imho the skipping of the stop command is a quirk someone came up with in EEPROM development and ever since all the data sheets repeat it and cause pitfalls like this. Issuing a I2C stop is so inexpensive code-wise that I always put it in even in assembly ;-). And to avoid *another* pitfall (f.ex. if the device does not /ack or is not present on the bus), I code it on PICs like: I2C_Stop: bcf Fi2c,Bsda // or equivalent TRIS manipulation bsf Fi2c,Bscl bsf Fi2c,Bsda Peter PS: Once burned forever careful ? What's the proper way to say this ?! -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body