Hello Achim & PIC.ers, I've had to bash my own way thru this recently meself... I cribbed, borrowed and stole whatever I could, then went back to the 16f87x manual and wound up with a set of master transmit <> receive routines that are *working* - perfectly well as far as I can tell. This app. has two Philips PCF8574 I2C general purpose byte-wide IO port chips. One (IO1) is dedicated to inputs only, for switch states, etc., while IO2 is output only, to drive a collection of panel LEDs. I have used private macros like :- bank0 ;use ram bank0 bank1 ;use ram bank1 movlf ;load literal to freg movff ;load freg1 to freg2 etc., these should need no introduction, but if they do, let me know.. Setup the ports by :- setup_i2c Invoke a IO1 port read by:- read_switches ;byte-wide result in freg`latest_switch_state' Invoke a IO2 port write by:- ;put desired byte into freg 'led_state' write_leds ;****************** I2C macros begin start_i2c MACRO ;[S] bank0 ;bank0 (bank0? names) be sure bcf PIR1,SSPIF bank1 ;bank1 bsf SSPCON2,SEN ;send i2c START [S] bit bank0 ;bank0 btfsS PIR1,SSPIF ;start bit cycle complete? goto $-1 endm enable_receive_i2c MACRO bank1 ;bank1 bsf SSPCON2,RCEN ;enable receiving at master 16f877 bank0 ;bank0 bcf PIR1,SSPIF btfsS PIR1,SSPIF ;sspbuf buffer full byte? goto $-1 endm stop_i2c MACRO ;[P] bank0 ;bank0 bcf PIR1,SSPIF bank1 ;bank1 bsf SSPCON2,PEN ;send i2c STOP [P] bit bank0 ;bank0 btfsS PIR1,SSPIF ;stop bit cycle completed? goto $-1 endm wait_for_ack_i2c MACRO bank0 ;bank0 bcf PIR1,SSPIF btfsS PIR1,SSPIF ;ACK received? goto $-1 endm setup_i2c MACRO ;setup mssp for i2c movlf 00101000b,SSPCON ;=0x028 bank1 movlf 10000000b,SSPSTAT movlf 01100000b,SSPCON2 movlf 00001010b,SSPADD bank0 endm read_switches MACRO ;io1 is inputs only start_i2c movlf 01000011b,SSPBUF ;send out io1 pcf8574 addr wait_for_ack_i2c enable_receive_i2c movff SSPBUF,latest_switch_state stop_i2c endm write_leds MACRO ;io2 is output only start_i2c movlf 01000100b,SSPBUF ;sned out io2 address, writing wait_for_ack_i2c movff led_state,SSPBUF wait_for_ack_i2c stop_i2c endm ;***************** I2C macros end >Date: Fri, 26 May 2000 09:05:15 +0200 >From: Achim Vollhardt >Subject: [PIC]: I2C master mode routines for 16F877 > > I am looking for some experienced guys working with the 16F877 as >master > with I2C protocol.. I have tried to figure out some working routine >from > the datasheet, but in contrast to the USART programming there is no > 'to-do' list for I2C Master mode.. can anyone help me out as my own > routines don't work ? > > Thanks in advance! > Achim Vollhardt > > avollhar@physik.unizh.ch > Hope this all makes sense, best regards, John e-mail from the desk of John Sanderson, JS Controls. Snailmail: PO Box 1887, Boksburg 1460, Rep. of South Africa. Tel/fax: Johannesburg 893 4154 Cellphone no: 082 469 0446 email: jsand@pixie.co.za Manufacturer & purveyor of laboratory force testing apparatus, and related products and services.