Hello Roland & PIC.ers, ----- Original Message ----- From: "Roland" To: "Microcontroller discussion list - Public." Sent: Wednesday, June 01, 2005 6:41 AM Subject: [PIC] more on I2C on 18F452 > Hi > > I've changed my code from bit-bang to using the MSSP for the I2C bus. > I Implemented the code as attached by others in the pic w-r_i2c.gif, and it works fine. > I see, however, that there is no provision for error trapping > > In the typical snippet below, > > mov WORD, SSPBUF ;word address write > i2cwrite_w btfsc SSPSTAT, r_w > bra i2cwrite_w > > would the strategy be?; > - use a timer to track the event for a few ms, then exit if hung? > - how does one usually recover an errant I2C bus? > send a few 'stop' conditions? > or clear the SSPEN > > > > > Regards > Roland Jollivet > > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > > All my i2c macros have timer loops in them to allow ..stretch. There is also allowance for error traps by way of detecting time-out, but it seems these never actually get invoked in service and the products using this scheme work well. So, I assume the mssp is fairly bulletproof and likewise i2c. The mssp format is e.g. :- read_switches MACRO start_i2c ;macro movlf 01000011b,SSPBUF ;macro wait_for_ack_i2c ;macro enable_receive_i2c ;macro stop_i2c ;macro endm Hope this helps, holler if you need more. best regards, John email from the desk of John Sanderson. web: www.jscontrols.co.za email: john@jscontrols.co.za Tel: (027) 11 893 4154 Cell: 082 741 6275 Manufacturer and purveyor of force testing machines and apparatus. -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist