simulating i2c

johnlong

Senior Member
Hi All
I am trying to simulate the return actions of a 28X2 as a slave
I am sendig 23,45,111 from the serial terminal simulator but
I am recieving 95 and 104 respectivally not the 3 bytes I am expecting
have altered the simulator settings to %xxxxxxx0 i2cfast, i2cbyte check box
Code:
TH: 
	photo=0:dry=0:RH=0
	hi2csetup i2cmaster,pic, i2cfast, i2cbyte '%1100000 for 28x2 slave
	hi2cout 0,("c","h")
	pause 3000
	do
	hi2cin 0,(dry,RH,photo)'b48,b50,b23 
	pause 500
	sertxd("Dry="," ",#dry," ","RH="," ",#RH," ","photo="," ",#photo,cr,lf)
loop until photo<>0

	return
can the simulater be used for i2c communications

regards john
 

lbenson

Senior Member
Don't know about your 95, but 104 is the decimal value for the ascii charactor, "h", which is what you wrote in position 2 (address 1), so would be expected. For the "c" you wrote, you should be seeing 99 with #dry. You didn't write a third charactor, so would expect 0 to be returned for photo--the NUL character--which should print as 0 with your #photo.

If you are expecting charactors, you should omit the "#" in your sertxd command.

For the ASCII charactor table, see: http://www.asciitable.com/

Your code works for me in simulation (giving 99 for the first byte returned by hi2cin).
 
Last edited:

hippy

Technical Support
Staff member
Ditto; works for me -
Code:
#Picaxe 28x2
Do
  For b0 = "a" to "z"
    hi2csetup i2cmaster, $C0, i2cfast, i2cbyte
    hi2cout 0,( b0, "b", "c")
    pause 1000
    hi2cin 0,( b1, b2, b3 )
    SerTxd( b1, TAB, b2, TAB, b3, CR, LF )
  Next
Loop
 
Top