Look at the code that Alan Pearce indicates, and compare it with Application note AN734a from Microchip's site.=20 If you want to program in PicBasic, you should examine the files that I make available at www.astrosurf.com/soubie/microcontroleurs.htm: they are for a 16F876 but would work for other chips, such as the 18F series. You only need modify a couple of things to reuse them, e.g. the size of the receive and transmit buffers, and of course the included file where the application specific processing takes place. However, you will need to use "fast interrupts" routines for this , such as those by Timothy Box for the 16F and Darrel Taylor's for the 18F. The Master 16F877 can be programmed in PicBasic using i2cread and i2Cwrite.=20 Send an email if you have trouble locating them.=20 On Wed, 21 Jan 2004 13:39:04 -0000, Peter Duthie wrote on [PIC:] i2c assembler routines: >Hello everyone. I have a project where 4 slaves (pic16F876) and 1 master >(pic16F877) will be using i2c to communicate. I'm pretty new to pics but >can do PicBasic easily enough. But the PicBasic i2c stuff doesn't work >for my project (why not?) and I need to use assembler to read and write >between the 16F877 and 16F876's. I've spent a few days on this already >without success and I'm getting confused about when to send Acks, Nacks, >Stops, etc. If some kind person could list the sequence of events for an >i2c read and an i2c write (on the master side - I believe the slave code >is fine) and what needs to be done in software and when it needs to be >done. I will be eternally grateful. > > > >Although I need to do the read/write's in assembler I'll be doing the >rest of the code in PicBasic (for speed: the code needs to be ready for >shipping at the end of this month). The most urgent difficulty is >getting the read to work. Here's where I'm at - at the moment (it >doesn't work properly). Thank you very much for reading this and helping >out. > > > >loop: > > Pause 1000 > > currentAddress =3D 17 > > call SetStart > > call i2cSendAddress > > call i2cReadByte > > inData[0] =3D SSPBUF > > call i2cAck > > call i2cReadByte > > call i2cNack > > call i2cStop > > goto loop ' Do >it forever > >end > > > >asm > >_SetStart > > banksel PIR1 > > bcf PIR1, SSPIF > > banksel SSPCON2 > > bsf SSPCON2, SEN > > btfsc SSPCON2, SEN > > goto $-1 > > bcf STATUS, RP0 > > return > >endasm > > > >asm > >_i2cSendAddress > > bcf STATUS, C > > movf _currentAddress, w > > banksel SSPBUF > > movwf SSPBUF > > banksel SSPSTAT > > btfsc SSPSTAT, R_W > > goto $-1 > > bcf STATUS, RP0 > > return > >endasm > > > >asm > >_i2cReadByte > > banksel SSPCON2 > > bsf SSPCON2, RCEN ;generate read >condition > > btfsc SSPCON2, RCEN > > goto $-1 > > bcf STATUS, RP0 > > return > >endasm > > > >asm > >_i2cStop > > banksel PIR1 > > bcf PIR1, SSPIF > > banksel SSPCON2 > > bsf SSPCON2, PEN > > banksel PIR1 > > btfss PIR1, SSPIF > > goto $-1 > > > >endasm > > > >asm > >_i2cAck > > banksel SSPCON2 > > bcf SSPCON2, ACKDT > > bsf SSPCON2, ACKEN > > bcf STATUS, RP0 > > return > >endasm > > > >Cheers, > >Peter > > > >P Duthie, software engineer, CDLtd * Xrobert.soubie@free.frX (veuillez supprimer les "X") * http://www.astrosurf.com/soubie * Au royaume des aveugles, les borgnes sont mal vus... - P.Dac -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu