i2c help please

Compy

New Member
#1
Hi, This is my first project and first post. Apologies if its in the wrong place or format.
I have linked two 20x2 chips together as master and slave using i2c . I have lifted some code from the site and got the master to write and the slave to read.

Master code:
init: hi2csetup i2cmaster, %10100000, i2cslow, i2cbyte
MAIN:
b1 = 4
hi2cout 0,(b1)
pause 500
GOTO MAIN

Slave code:
init: hi2csetup i2cslave, %10100000
MAIN:
IF HI2CFLAG = 0 THEN MAIN
HI2CFLAG = 0
GET HI2CLAST,B1
SERTXD ("#B1 ",#B1,CR,LF)
GOTO MAIN

This all works fine and the number 4 is displayed so I presume the electronics is OK.
I want to get the slave to write out a value and for the master to read it - the reverse of the working code. I cannot get this to work and assume I am missing something very basic.
Eventually I want to add in more slaves for the master to read from.
The code I have is:
Slave code:
init: hi2csetup i2cslave, %10100000
MAIN:
b0 = 1
put 0,b0
GOTO MAIN

Master code:
init: hi2csetup i2cmaster, %10100000, i2cslow, i2cbyte
MAIN:
hi2cin 0,(b0)
SERTXD ("#b0 ",#b0,CR,LF)
GOTO MAIN

All I get from the master is 255.

Thanks
 
Top