Comunication I2C between 20X2

David Bonet

New Member
Hi everyone,

I have one question about how to program master and slave device to work with i2c protocol.

My sistem use one master device and a certain number of slave devices. The objective of the slave devices is store a data and send it to the master when it demands. To store this data, I'm using a 24C08 memory connected with I2C protocol.

Then, my question is: Is there any problem if I connected the bus i2c from all boards and the memories? After test a little bit, comunication between picaxes was ok when I don't read the data in the memory. Maybe, if I setup one pic to work as a slave in I2C protocol, i can't use it as a master to read from memory. Can anybody told me if this is rigth?

This is a example about what I would like to do:

-- SLAVE --
hi2csetup i2cslave, %00000010

main:

i2cslave %10100000, i2cfast, i2cbyte
readi2c 0,(b1) 'Read in memory and save the value in b1

put 2, b1 'Put this value in scratchpad
goto main

-- MASTER --
hi2csetup i2cmaster, %00000010, i2cfast, i2cbyte

main:
hi2cin [%00000010],2,(b1)
debug b1
goto main

But in master device, I allways has 255 in b1 variable.

Could anybody help me, please?

Kind regards,

David
 

hippy

Ex-Staff (retired)
-- SLAVE --
hi2csetup i2cslave, %00000010
main:
i2cslave %10100000, i2cfast, i2cbyte
The problem here is that you set up the PICAXE as a slave ( HI2CSETUP I2CSLAVE ) but then you redefine the PICAXE as a master ( I2CSLAVE => HI2CSETUP I2CMASTER ). This may partly be a result of the terminology and mixing of commands and we recommend using the HI2CSETUP command.

For the PICAXE to be used as a slave after being a master you will have to reissue the HI2CSETUP I2CSLAVE command, and you will also have to ensure the PICAXE is a slave when you attempt to read it from the other PICAXE as a master at the time.
 
Top