hi2cin problem

shoei600

New Member
Dear forum,

I'm sending simple single byte from a 28x2 to a 20x2 using hi2cout which works without any problems. I can't however seem to read the status of a memory location when using hi2cin.

The code below is just for test and I have proven the byte variable changes in the slave. Is there something I'm missing?

Just for completeness I have both clock and data lines tied high with 10k resistors also.

Many thanks in advance.

Master code
Code:
#picaxe 28x2
setfreq m8
hsersetup B38400_8, %001
hintsetup %00000111
hi2cSetup i2cMASTER, %10100000, i2cSLOW, i2cBYTE

Main:
pause 300
bptr=60
	hi2cin b1,(@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptr)
	pause 100
	hserout 0,("bptr=",#@bptr,13,10)
goto Main
Slave code:
Code:
#picaxe 20x2

let dirsC=%00001111

pinsC=$FF
hI2cFlag = 0

init: hi2csetup i2cslave, %10100000
let pinsC = %11111111 'Relays OFF

main:
'bptr=57
pause 1000
let pinsC = %11111111 'Relays OFF
b1=0
pause 1000
let pinsC = %11111110 'Relay 1 ON
b1=1
'@bptr=1
pause 1000
let pinsC = %11111101 'Relay 2 ON
b1=2
'@bptr=2
pause 1000
let pinsC = %11111011 'Relay 3 ON
b1=3
'@bptr=3
pause 1000
let pinsC = %11110111 'Relay 4 ON
b1=4
'@bptr=4
goto main
 

Buzby

Senior Member
Hi Shoei,

The I2C reads from the scratchpad in the Slave, not the variables.

You need to use 'ptr' and '@ptr', not 'bptr'.

Read in the manual about the scratchpad.

Cheers,

Buzby
 

westaust55

Moderator
I think shoei600's statement arises from the following line under the hi2cin command information:

Variable(s) - receives the data byte(s) read.

This is valid when the PICAXE is the Master device on the i2c network.

If shoei600 also reads in the section for the hi2csetup command about PICAXE as slave devices,
then the use of the scratchpad is clear:

When in slave mode all i2c functions of the slave PICAXE chip are completely automatic. An i2c master can read or write to the slave PICAXE chip as if it was a 128 (X1, 20X2) or 256 (X2) byte 24LCxx series EEPROM, with the scratchpad area acting as the memory transfer area.
 

shoei600

New Member
I must say, I had re-read all about scratchpad and 12c commands several times over before posting but clearly missed the specific about the scratchpad. Having said that, as you'll see from the "bptr" entries remmed out I had been trying all along with the scratchpad, just the wrong one.

It think it is the location in this statement that misleads and could be better presented as scratchpad location.

HI2CIN location,(variable,...)
Location - is a optional variable/constant specifying a byte or word address.

Nevermind, we live and learn. Hindsight is wonderful and I hope the manual develops a little further to be more specific. I'm just happy that you guys are on hand to help out from time to time. Picaxe itself is great but it is the value of the forum members here is what makes it superb.

Thanks all.
 
Last edited:
Top