I need help with i2c communication.

Jamcof

New Member
Hello, I am just a beginner with i2c :)
So I am trying to make communication with i2c between two PICAXE chips. (08M2 as Master and 28X2 as Slave.)

I think that I have some wrong with my two codes.
Code:
main:
	hi2csetup i2cmaster, %10100000, i2cslow, i2cbyte
	do
  	if pinC.3 = 1 then
    	pause 500
    	hi2cout 0, ( 2 )
  	endif
  	if pinC.4 = 1 then
    	pause 500
    	hi2cout 0, ( 3 )
  	endif
	loop
	stop
so that's the Master's code, and yes it has a button to send message to light up an LED on the other chip (28X2).


Code:
symbol varA = w0

main:
	hi2csetup i2cslave, %10100000
	do
  	hi2cin 0, ( varA )
  	if varA = 3 then
    	high C.0
  	endif
  	if varA = 2 then
    	low C.0
  	endif
	loop
	stop
And this is slave's code.
So my idea was that, when pin 4 (on master) is high then it turns on the LED on slave. And pin 3 to turn off LED.


My wiring should be fine. I have two 4k7 pull-up resistors on SCL & SDA.

So hopefully you understood my english.:)

Thanks.
 

hippy

Technical Support
Staff member
Your slave (20X2) program should not be using HI2CIN. The values sent from your master (08M2) will automatically be placed in the 20X2's scratchpad area.
 

inglewoodpete

Senior Member
Your slave (28X2) program should not be using HI2CIN. The values sent from your master (08M2) will automatically be placed in the 28X2's scratchpad area.
To expand on hippy's reply, if the i2c communication is working (It looks as if it should work.), the data from the master should magically appear in location 0 of the slave. So make two changes to your slave's code to this:
Code:
[color=Navy]#PICAXE [/color][color=Black]28X2[/color]
[color=Navy]#Terminal 9600[/color]
[color=Green]'[/color]
[color=Blue]symbol [/color][color=Black]varA [/color][color=DarkCyan]= [/color][color=Purple]b0           [/color][color=Green]'i2c only transfers byte values[/color]

[color=Black]main:
   [/color][color=Blue]hi2csetup i2cslave[/color][color=Black], [/color][color=Navy]%10100000
   [/color][color=Blue]do
      Get [/color][color=Navy]0[/color][color=Black], varA          [/color][color=Green]'Fetch value stored in Scratchpad location 0 and place it in register varA (b0)
      [/color][color=Blue]SerTxd ([/color][color=Black]#varA, [/color][color=Red]"; "[/color][color=Blue]) [/color][color=Green]'Report the value to the PE serial terminal (for debugging)
      [/color][color=Blue]if [/color][color=Black]varA [/color][color=DarkCyan]= [/color][color=Navy]3 [/color][color=Blue]then
         high C.0
      endif
      if [/color][color=Black]varA [/color][color=DarkCyan]= [/color][color=Navy]2 [/color][color=Blue]then
         low C.0
      endif
   loop
   [/color][color=Green]'stop    not required[/color]
 
Top