Hi , i connect 2 pic (16f877a as master - 16f819 as slave) and can sent one byte only to my slave side correctly...
How can i read the second byte on my slave side? the code is but not work!:
master:
Code:
I2C1_Start()
I2C1_Wr(0xD0) the slave code (16f819)
I2C1_Wr(lo(send)) the low part of send word
I2C1_Wr(hi(send)) the high part of send word
I2C1_Stop()
slave:
Code:
if sspstat.D_A = 1 then ' data arrived no address
lo(rxbuffer)= sspbuf read first sent byte
hi(rxbuffer) = sspbuf read second sent byte
j = SSPBUF empty ssbuf
return
else
j = SSPBUF if address arrived empty the SSBUF
return
end if
Then pir1.sspif set to 1 the one byte ready to read! i read 2 byte immediately! we must set pointer for string of data then recieveing and add the pointer and save the bytes in my sample is 2 byte only but is clearly to expand the code . good luck and enjoy
Slave code:
Code:
sub procedure interrupt
if pir1.sspif = 1 then
pir1.sspif = 0
INTCON = %00000000
if (sspstat.D_A = 1) and (sspstat.bf=1) then
if pointer=0 then
lo(rxbuffer)=sspbuf
pointer=1
goto exit_int
end if
if pointer=1 then
hi(rxbuffer)=sspbuf
pointer=0
goto exit_int
end if
goto exit_int
return
end if
end if
exit_int:
j = SSPBUF
INTCON = %11000000
return
end sub