Shop OBEX P1 Docs P2 Docs Learn Events
Help Connecting 2 bs2p40's through an eeprom — Parallax Forums

Help Connecting 2 bs2p40's through an eeprom

blacksheep45blacksheep45 Posts: 41
edited 2009-03-19 13:52 in BASIC Stamp
I am using the following programs to get 2 bs2p40s to communicate via an eeprom and i was wondering if anyone could tell me why this is not working.

The first program is for the master stamp that sends out the value that the slave stamp will read out.

1st (Master):

' {$STAMP BS2p}
' {$PBASIC 2.5}
inP·· PIN 15
outP· PIN 14
v VAR Byte
y VAR Byte
x VAR Byte
Setup:
· HIGH outP····················· ' Set pin high to be a serial port
· PAUSE 100······················ ' Pause for Serial LCD to initialize
start:
DO
IF outP = 1 THEN
· v = 63
· I2COUT 0, $A0, 0\3, [noparse][[/noparse]DEC v]
· DEBUG "out is ",DEC v
· PAUSE 100
· outP = 0
· PAUSE 100
· LOW outP
ELSE
· GOTO start
ENDIF
LOOP

2nd (Slave):

' {$STAMP BS2p}
' {$PBASIC 2.5}
Lcd············ PIN···· 7
inP············ PIN···· 14
outP··········· PIN···· 15
LcdCls········· CON···· $01···· ' clear the LCD
LcdHome········ CON···· $02···· ' move cursor home
LcdCrsrL······· CON···· $10···· ' move cursor left
LcdCrsrR······· CON···· $14···· ' move cursor right
LcdDispL······· CON···· $18···· ' shift chars left
LcdDispR······· CON···· $1C···· ' shift chars right
LcdDDRam······· CON···· $80···· ' Display Data RAM
LcdCGRam······· CON···· $40···· ' Character Generator RAM
LcdLine1······· CON···· $80···· ' DDRAM address of line 1
LcdLine2······· CON···· $C0···· ' DDRAM address of line 2
baud··········· CON···· 1021
v VAR Byte
x VAR Byte
y VAR Byte


Setup:
· HIGH Lcd····················· ' Set pin high to be a serial port
· PAUSE 100······················ ' Pause for Serial LCD to initialize

start:
DO
IF inP = 0 THEN
· I2CIN 0, $A1, 0\3, [noparse][[/noparse] DEC x]
· PAUSE 50
· WRITE 0, x
· READ 0, x
· DEBUG DEC x,CRSRRT
· SEROUT Lcd, baud, [noparse][[/noparse]24,12,17]
· PAUSE 100
· SEROUT Lcd, baud, [noparse][[/noparse]DEC x]
· PAUSE 100
· HIGH inP
ELSE
· GOTO start
ENDIF
LOOP

The SDA pin on the EEPROM is connected to pin 0 on both stamps.
The SCL pin on the EEPROM is connected to pin 1 on both stamps.
WP, A0, A1, A2 and Vss on the EEPROM is connected to the Vss of both stamps.
Vdd on the EEPROM is connected to the Vdd of both stamps.

Comments

  • roadrunner3groadrunner3g Posts: 36
    edited 2009-03-19 11:30
    ????serin/serout where???? try serout (master), serin (slave)
    it looks like i2cin/out is for stamp to i2c chip, NOT stamp to stamp.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-19 13:52
    roadrunner3g is correct. The built-in I2C statements support only master mode. They cannot be used to make a Stamp appear to be an I2C slave, so you can't do what you want with them. It is possible to write code that uses statements like HIGH / LOW to do what you want, but very very slowly. It's much better to use SERIN and SEROUT to communicate between two Stamps and there is sample code for this available in the Nuts and Volts Columns.
Sign In or Register to comment.