12c communications

hax

New Member
Hi all,

I'm working on having two picaxe chips (20x2) communicate with i2c. Things are going well but I have a problem.

The master runs this demo code (the final product will have 8 different variables that will change depending on some other sensors):

b1=1
b2=2
b3=3
b4=4
init: hi2csetup i2cmaster, %10100000, i2cslow, i2cbyte
main:
hi2cout 1,b1
hi2cout 2,b2
hi2cout 3,b3
hi2cout 4,b4
pause 500 ; wait a while
goto main


The slave runs the code:

init: hi2csetup i2cslave, %10100000
main:
get 1,b1
get 2,b2
get 3,b3
get 4,b4
wait 1
debug
goto main


The problem I have is I want to get rid of the wait 1 command, for faster throughput. It works down to pause 100 but really any lower than that, the values freeze.

Is this because the slave picaxe can't read and write to the scratchpad simultaneously?

What is a good way to get around this problem? I know I can set a flag, but that is just for any last byte received, isn't it? The slave picaxe needs to know immediately when the last (get 4) value has been updated in order to do some time-critical measuring of sensors.


Thanks for your help!
 

Technical

Technical Support
Staff member
Yes, the slave needs time to save the values. Note also the debug command is a 'very long' command taking quite a while to process.
 

PhilHornby

Senior Member
I'm working on having two picaxe chips (20x2) communicate with i2c. Things are going well but I have a problem.
...
...
The problem I have is I want to get rid of the wait 1 command, for faster throughput. It works down to pause 100 but really any lower than that, the values freeze.
I did something similar in my very 1st Picaxe project - like you I found the demo programs on the forum worked a treat, but the minute I added in useful work, I started missing data. I ended up with Checksums, Sequence Numbers, handshaking lines and finally got it to work.

While I learned a lot in the process; with hindsight, Serial Comms. and the 20X2's background receive capability would probably have been a much simpler approach!
 
Top