readi2c?

jonphenry

New Member
Im tinkering with i2c. I wrote a small program just for testing. It reads adc0 and stores its value in b0, then stores b0 at b1 on my i2cslave(24LC16B). I then try to use readi2c to read the value from the eeprom and display it on my lcd readout.

main:

readadc 0,b0
i2cslave %10100000, i2cslow, i2cbyte
writei2c b1,(b0)
pause 20
i2cslave %10100000 ,i2cslow, i2cbyte
readi2c b1,(b4)
pause 20
serout 7,N2400,(254,128,#b4)
goto main


My problem is it locks up. Even just running this code in the simulator locks it up on the readi2c command. Anyone see this before?
 

BCJKiwi

Senior Member
b1 is a variable
b1 represents the address in the chip of the register you are writing to or reading from.
You will need to initialise the variable b1 to the starting address you want.
See the examples in the i2c tutorial doc from Rev-Ed.

e.g. (not tested!) to allow 60 bytes to be written
main:
i2cslave %10100000, i2cslow, i2cbyte
for b1=0 to 59
readadc 0,b0
writei2c b1,(b0)
pause 20
i2cslave %10100000 ,i2cslow, i2cbyte
readi2c b1,(b4)
pause 20
serout 7,N2400,(254,128,#b4)
next b1
goto main
 
Last edited:

jonphenry

New Member
Thanks BCJ I got it figured out.

Its kinda weird. Using the code I initially posted,when set on 28X1 mode, it locks up on the readi2c command. When set on 18X mode, it runs fine.
 
Top