Bidirectional Communication
A Krish
Posts: 27
Hey guys ...
I am working on a project where I need to transmit data between two Bs2's ...·
Problemt Statement:
Communciation between the BS2 is wireless that is using 27981 (RF Receiver) and 27980 (RF Transmitter). Bs2 "A" sends a data to Bs2 "B" inturn once Bs2 "B" receives the data it should send a data to Bs2 "A".
My Problem:
I am able to transfer data from Bs2 "A" to Bs2 "B" but for the return loop I am unable to get the data back ... i.e. I am unable to get the data from Bs2 "B" to Bs2 "A".
I am enclosing below·the simple test code which I have been using for the data communication testing purpose...
Bs2 "A"
' {$STAMP BS2}
' {$PBASIC 2.5}
Init:
x VAR Word
y VAR Word
Transmit:
x = 1000······· ' data to be communicated to Bs2 "B"
· PULSOUT 6, 1200
· SEROUT 6,16468,[noparse][[/noparse]"!",x.HIGHBYTE,x.LOWBYTE]
· DEBUG ? x
Receive:
· DO
··· HIGH 0
··· SERIN 12,16468,[noparse][[/noparse]WAIT("!"),y.HIGHBYTE,y.LOWBYTE]
··· DEBUG ? y
··· LOW 0
· LOOP UNTIL (y = 100)··· ' data from Bs2 should be 100
RETURN
Bs2 "B"
' {$STAMP BS2}
' {$PBASIC 2.5}
Init:
x VAR Word
y VAR Word
Receive:
··· DO WHILE ( x <> 1000)
········ HIGH 0
········ SERIN 12, 16468,[noparse][[/noparse]WAIT("!"),x.HIGHBYTE,x.LOWBYTE]
········ LOW 0
···LOOP
Tranamsit:
········ DEBUG ? x
········ DO
········ y = 100····· ' data to be communicated to Bs2 "A"
········ PULSOUT 6,1200
········ SEROUT 6,16468,[noparse][[/noparse]"!",y.HIGHBYTE,y.LOWBYTE]
········ DEBUG ? y
········ LOOP
RETURN
Can anyone let me know what I am doing wrong ... Or any suggestion that could help me out .. Thanx in advance ....
···
I am working on a project where I need to transmit data between two Bs2's ...·
Problemt Statement:
Communciation between the BS2 is wireless that is using 27981 (RF Receiver) and 27980 (RF Transmitter). Bs2 "A" sends a data to Bs2 "B" inturn once Bs2 "B" receives the data it should send a data to Bs2 "A".
My Problem:
I am able to transfer data from Bs2 "A" to Bs2 "B" but for the return loop I am unable to get the data back ... i.e. I am unable to get the data from Bs2 "B" to Bs2 "A".
I am enclosing below·the simple test code which I have been using for the data communication testing purpose...
Bs2 "A"
' {$STAMP BS2}
' {$PBASIC 2.5}
Init:
x VAR Word
y VAR Word
Transmit:
x = 1000······· ' data to be communicated to Bs2 "B"
· PULSOUT 6, 1200
· SEROUT 6,16468,[noparse][[/noparse]"!",x.HIGHBYTE,x.LOWBYTE]
· DEBUG ? x
Receive:
· DO
··· HIGH 0
··· SERIN 12,16468,[noparse][[/noparse]WAIT("!"),y.HIGHBYTE,y.LOWBYTE]
··· DEBUG ? y
··· LOW 0
· LOOP UNTIL (y = 100)··· ' data from Bs2 should be 100
RETURN
Bs2 "B"
' {$STAMP BS2}
' {$PBASIC 2.5}
Init:
x VAR Word
y VAR Word
Receive:
··· DO WHILE ( x <> 1000)
········ HIGH 0
········ SERIN 12, 16468,[noparse][[/noparse]WAIT("!"),x.HIGHBYTE,x.LOWBYTE]
········ LOW 0
···LOOP
Tranamsit:
········ DEBUG ? x
········ DO
········ y = 100····· ' data to be communicated to Bs2 "A"
········ PULSOUT 6,1200
········ SEROUT 6,16468,[noparse][[/noparse]"!",y.HIGHBYTE,y.LOWBYTE]
········ DEBUG ? y
········ LOOP
RETURN
Can anyone let me know what I am doing wrong ... Or any suggestion that could help me out .. Thanx in advance ....
···
Comments
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Involvement and committment can be best understood by looking at a plate of ham and eggs. The chicken was involved, but the pig was committed. ANON
Really appreciate your promp response ..... I changed the Baud rate as you have suggested ... but still I am unable to receive back the data ... Once gain .. I am able to get the data from Bs2 "A" to Bs2 "B" .. but I am unable to get the data from Bs2 "B" to Bs2 "A" ...
Is there anything else I should change ??
I trust you are aware there is an infinite loop in the second program ("BS-2 B"), in the SEROUT section?
The RETURN statement in the "BS-2 B" program can also be removed, as it's doing nothing useful, UNLESS you meant to use the transmit routine as a GOSUB routine. In that case you need to add a GOSUB statement in the receive routine, within the LOOP statement.
Let us know how you make out with that information.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Involvement and committment can be best understood by looking at a plate of ham and eggs. The chicken was involved, but the pig was committed. ANON
DEBUG statements in these progs are being used to check if the control is actually going to the concerned functions ...
I know that BS2 "B" is continuosly polling data ... thats deliberate ... However ... when I added GOSUB Receive .. Now I am able to receive data by BS2 "A" .... but its garbage value ..
I am pasting the code that I have now in place..
Bs2 "A"
' {$STAMP BS2}
' {$PBASIC 2.5}
Init:
x VAR Word
y VAR Word
Transmit:
x = 1000 ' data to be communicated to Bs2 "B"
PULSOUT 6, 1200
SEROUT 6,16468,[noparse][[/noparse]"!",x.HIGHBYTE,x.LOWBYTE]
DEBUG ? x
Receive:
DO
HIGH 0
SERIN 12,16468,[noparse][[/noparse]WAIT("!"),y.HIGHBYTE,y.LOWBYTE]
DEBUG ? y
LOW 0
LOOP UNTIL (y = 100) ' data from Bs2 should be 100
RETURN
Bs2 "B"
' {$STAMP BS2}
' {$PBASIC 2.5}
Init:
x VAR Word
y VAR Word
Receive:
DO WHILE ( x <> 1000)
HIGH 0
SERIN 12, 16468,[noparse][[/noparse]WAIT("!"),x.HIGHBYTE,x.LOWBYTE]
LOW 0
LOOP
Tranamsit:
DEBUG ? x
DO
y = 100 ' data to be communicated to Bs2 "A"
PULSOUT 6,1200
SEROUT 6,16468,[noparse][[/noparse]"!",y.HIGHBYTE,y.LOWBYTE]
DEBUG ? y
GOSUB Receive
LOOP
I am still not able to receive exact data i.e. y = 100 at BS2 "A" DEBUG terminal ..
You removed the RETURN from the "BS-2 B" program, but the same thing exists in the other program "BS-2 A". Please remove it too, or again, make the Receive routine a GOSUB routine.
NOTE:
The two commands are RELATED - GOSUB...RETURN. You can not use GOSUB without RETURN, and you can not use RETURN without a GOSUB. Check the manual for additional information.
First you were using x = 1000 for data. Now you are using y = 100 for data. Let's try to be consistent.
For future reference, please make only ONE CHANGE AT A TIME. It makes troubleshooting much easier.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Involvement and committment can be best understood by looking at a plate of ham and eggs. The chicken was involved, but the pig was committed. ANON
Please check the code carefully ... x has always been 1000 and y has always been 100 ...
I checked the GOSUB thing ... I am now starting to receive data at the Bs2 "A" end ... but its all garbage value .. any suggestions !!
If that's not your situation, then that doesn't apply.
"A"
Time_out:
SEROUT 6,16468,[noparse][[/noparse]"!",DEC x,CR]
SERIN 12,16468,300,Time_out,[noparse][[/noparse]WAIT("!"),DEC4 y]
If "A" does not receive data within 300 mS it will re=transmit "x"
Stamp "B" does not have to be quite as "intelligent", all "B" has to do is sit waiting for a value then transmit one back.
"B"
SERIN 12,16468,[noparse][[/noparse]WAIT("!"),DEC4 x]
PAUSE 50
SEROUT 6,16468,[noparse][[/noparse]"!",DEC y,CR]
I would forget the comparisons for now and just debug the values you are sending and receiving to make sure the data is as you would expect. Serial communication really slows the Stamp down the use of the time out instruction can alleviate that greatly.
Jeff T.
http://www.parallax.com/Portals/0/Downloads/sw/433RadioCRCV1.0.zip
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.iElectronicDesigns.com
·
Thanx a lot for ur help ..
I tried ur suggestions .. now I am able to receive data at Bs2 "A" i.e. the value of y ... but it is garbage value ... it is stil not receiveing 100 (as assigned at Bs2 "B") ... Can u plzzzz suggest me .. how should I proceed ... I am pretty new to this environment .. would really appreciate if you could help me out ....
I understand the time out thing .... but right now .. i am looking to get the data correctly ...
Check out the code at Bean's link.
Jeff T.
I am putting the code here itself .. hope u cna help me out ...
BS2 "A"
' {$STAMP BS2}
' {$PBASIC 2.5}
Init:
x VAR Word
y VAR Word
Transmit:
x = 1000
PULSOUT 6, 1200
SEROUT 6,16780,[noparse][[/noparse]"!",DEC x,CR]
DEBUG ? x
GOSUB Receive
END
Receive:
DO
HIGH 0
SERIN 12,16780,[noparse][[/noparse]WAIT("!"),DEC4 y]
DEBUG ? y
LOW 0
LOOP
RETURN
' {$STAMP BS2}
' {$PBASIC 2.5}
Init:
x VAR Word
y VAR Word
Receive:
DO
HIGH 0
SERIN 12,16780,[noparse][[/noparse]WAIT("!"),DEC4 x]
LOW 0
GOSUB Transmit
LOOP
Transmit:
DEBUG ? x
y = 1000
PULSOUT 6, 1200
SEROUT 6,16780,[noparse][[/noparse]"!",DEC y,CR]
DEBUG ? y
RETURN
1) I always had to transmit at least 4 "sync" characters before the real message as it took the receiver that long to "get in sync"
2) a small delay of maybe 100ms between transmitting and receiving may be helpful.
Here's a question: I guess you have the same circuit for each stamp (stamp + receiver + transmitter). What happens if you swap the code on the stamps--does the problem still exist?