i2c betwean multiple PICAXE chips

guyba

Member
Hi
I"m very new to this.
I have read carefully the datasheets and all documentation regarding the i2C protocol. All of which talk about networking a picaxe master to external devices.

Can I network the picaxe to otehr picaxes using i2c ?
if so how to I give the slaves an address ? all the examples tal about devices that have address. I want to network 10 picaxes to one master using the i2c protocol.

thanks
Guy
 

lahaye

Member
Hello Guy,

The same question came to my mind too.
Please take a look at Manual part 2 Page 50 (Hi2c setup - slave mode), not i2c setup.

From the manual 2:

Code:
The slave address is the address that is used by the PICAXE chip for identification.
It can be a number between 0 and 127, but must be held in bits 7 to 1 of the
address (not bits 6 - 0) e.g. %1010000x. Bit0 is the read/write bit and so ignored.
If you are not sure which address to use we recommend the ‘standard i2c
EEPROM’ address which is %10100000. Some special i2c addresses, such as 0,
have special meanings under the i2c protocol (0 = broadcast all) and so are not
recommended as they may cause unexpected behaviour on third party devices.

Please note that the hi2c command is only available for the 28X1/40x1
I hope this helps

Regards
Florian
 
Last edited:

hippy

Ex-Staff (retired)
Any PICAXE can be an I2C Master; easiest with those which support the I2CSLAVE command otherwise it means bit-banged I2C driver software and some fiddling with hardware designs.

Only the 28X1 and 40X1 ( plus future 28X2 and 40X2 ) can function as I2C slaves.
 

guyba

Member
Thanks for that...
I was trying to get the network going lasy night but it just doesnt work for me... I"m not sure how ro recieve the variable over the network with the salve. I looked at teh data sheet examples and referance manual and I"m not sure why it doesnt. I hope that its ok that I post the lines of code here so you can tell me what did i miss. Thanks in advance
Guy
---------------------------------------
I have a master and 2 slaves

I set up the master and send 2 variable this way -

HI2CSETUP I2CMASTER, %10100000, i2cslow, i2cbyte
hi2cout (9) 'send to first slave
hi2cout %11100000,(8) 'new slave

and for testing purposes I try to recieve the varialbe, varify it and light and LED

slave 1
HI2CSETUP I2CSLAVE, %10100000 'set up the slave address
hi2cin (b1)
if b1=9 then flash 'goes to a routine to flash a LED


slave 2
HI2CSETUP I2CSLAVE, %11100000
hi2cin (b1)
if b1=8 then flash 'goes to a routine to flash a LED
 

BCJKiwi

Senior Member
Suspect the issue may be that the slaves are just that - slaves. All the i2c activity happens in the master only.

i.e. the master can read and write to the slaves.

For the slave to act on the data written, this part of the manual would seem to apply (Manual2, bottom of Page50);
Description:
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) or 256 (X2) byte 24LCxx series EEPROM, with the scratchpad area
acting as the memory transfer area. The master can read the slave PICAXE chip at
any time. This does not have any effect on the slave PICAXE program.
However when the master writes to the slave PICAXE memory the ‘hi2cflag’ is set
and the last address written to is saved in the ‘hi2clast’ variable. Therefore by
polling the hi2cflag bit (or using setintflags to cause an interrupt) the PICAXE
program can take action when a write has occurred. The hi2cflag must be cleared
by the user program after use.
Example:
main:
if hi2cflag = 0 then main ‘ poll flag
hi2cflag = 0 ‘ reset flag
get hi2clast,b1 ‘ get last byte written
let outpins = b1 ‘ set output pins
goto main
hi2csetup master is issued in the master, and hi2csetup slave commands are issued in the slaves just to set up i2c bus and addresses.

After that, i2c commands are only issued in the Master.
HI2CSETUP I2CMASTER, %10100000, i2cslow, i2cbyte ' only needed once at the start of the program.
Scratchpad starts at 0 so to write to slave1 location 10
hi2cout [%10100000],10,(9) 'send value 9 to scratchpad location10 in slave1
To read from slave1 at location 10
hi2cin [%10100000],10,(b1) 'read value 9 from scratchpad location10 into variable b1

To write to slave2 location 100
hi2cout [%11100000],100,(8) 'send value 8 scratchpad location100 in slave2
To read from slave2 at location 100
hi2cin [%11100000],100,(b2) 'read value 8 from scratchpad location100 into variable b2

At the slave no i2c commands are required.
To read what the master has written, or write new data for the master to read, utilise the hi2clast / hi2cflag and access the scratchpad directly with the commands found at in Manual2 page11 (overview) and get, put etc elsewhere in the manual.

Please note I have not actually done any multi PICAXE i2c only single PICAXE i2c to numerous other devices - so this is all from the manual as far as I understand it.
 
Last edited:

hippy

Ex-Staff (retired)
I'd suggest getting it working with one master and one slave before over complicating it with two slaves.
 

ValueAdd

Senior Member
I too found BCJKiwi's description to be very informative.
While I have not yet tried interconencting two PICAXE's the thoughts have been there.
 
Top