20X2 as an I2C Slave - Help Please

josefvs

New Member
Hi all,

I am trying to set-up a 20X2 as an I2C slave, reading an analogue value string (reading a potentiometer) it and transmitting the value over an I2C network (to a 28X2)

All I get is 161, regardless of the potentiometer position on 20X2

Can someone help?

Master Code

#picaxe 28x2
init:

hi2csetup i2cmaster, %10100000, i2cslow, i2cbyte


Read_Data:
hi2cin 0,(b0)

pause 100

sertxd ("Read From Slave",cr,lf)
sertxd (#b0,cr,lf)

goto Read_Data

Slave Code

#picaxe 20x2
init:
hi2csetup i2cslave, %10100000

main:
readadc b.0,b0
pause 100
put 0,b0
goto main
 

hippy

Ex-Staff (retired)
161 is $A1 in hexadecimal, your I2C device address with lsb set. This is often indicative of the I2C bus not being wired correctly, missing or incorrect value pull-ups, perhaps crossed-over or not connected SDA or SCL.
 

westaust55

Moderator
For X2 parts you must use the channel number, not the PIN number for READADC.

http://www.picaxe.com/BASIC-Commands/Analogue-InputOutput/readadc/

What value does the slave device see/ read from the analogue input?
Maybe try writing some specific values to the scratchpad location and see what the master reads - do they correspond?

I believe the PE makes some effort to resolve such incorrect channel designations but it may fail.
B.0 has a predefined value of 0 but pin B.0 is ADC channel 1 for a 20X2.
 

josefvs

New Member
Thanks,

The ADC values are fine, I have tried specific value in the scratchpad, after which I have used the following, all with good results:

#picaxe 20x2
init:
hi2csetup i2cslave, %10100000

main:
readadc b.0,b0
pause 100
put 0, b0
pause 50
get 0,b0
sertxd (#b0,13,10)
goto main

I have also tried reading data from a CMPS10 (I2C mode) on both master and slave to check functionality, both worked fine.

I am missing something...
 

josefvs

New Member
Major embarrassment, working late has it's costs.

Did not connect the grounds between the boards (two separate power supplies), works perfectly.

Thanks All.
 
Top