Nice code CREATV
It works for me.
I interconnected two 16F877 PICS per SDA and SCL.
heres the testing Code.
' PicBasic Plus I2C Master program - PIC16F877
Device 16F877
XTAL = 4
' Alias pins
Symbol SCL = PORTC.3 ' I2C clock line
Symbol SDA = PORTC.4 ' I2C data line
' Allocate RAM
Dim dataout As Byte ' Data out
'------------------------------------------------------------------------------------
' Main program loop
Main:
' Initialise ports and directions
ADCON1 = 7 ' All PORTA, PORTE pins to digital
dataout = 0 ' Will use this byte as signal
Again:
Toggle PORTA.0 ' Just to show PIC is Runing
I2Cout SDA,SCL, 2 , [ dataout ] ' Send data
DelayMS 10 ' I always use this delay after I2Cwrite
DelayMS 100 ' Pause for watching response on second pic
dataout = dataout + 1 ' increment value of
GoTo Again ' Do it all forever
On the Slave side i did a litlle variation , to see the data that was incoming ,...
' I2C write data to bus
i2cwr: datain = SSPBUF ' Put data into datain
SerOut PORTC.6,84,[ "In: ",DEC4 datain,13] ' added line
Return
'------------------------------------------------------------------------------------
Simulate it in Proteus .
All Ok.
Greetings