Shop OBEX P1 Docs P2 Docs Learn Events
Bidirectional Communication — Parallax Forums

Bidirectional Communication

A KrishA Krish Posts: 27
edited 2008-03-29 17:46 in BASIC Stamp
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 ....
···

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-03-28 05:56
    Try reducing the data rate from 9600 to 2400 baud. That means changing all of the SERIN/SEROUT statements to 16780 instead of 16468 as they are now.

    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
  • A KrishA Krish Posts: 27
    edited 2008-03-28 06:08
    Hi Bruce ...


    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 ??
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-03-28 06:24
    What do the DEBUG statements indicate when the program is running?

    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
  • A KrishA Krish Posts: 27
    edited 2008-03-28 06:37
    hmm ....

    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 ..
  • A KrishA Krish Posts: 27
    edited 2008-03-28 06:48
    oH ... i forgot to mention .. i have changed the Baudrate to 16780
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-03-28 06:55
    You went back to 9600 baud - hmm. I would have left it at 2400 baud for testing. I guess the DEBUG information is classified information ... hmm.

    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
  • A KrishA Krish Posts: 27
    edited 2008-03-28 07:40
    Well .. the baud rate is the same ..... i.e. 2400 ...
    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 !!
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-03-28 15:21
    If all you have is ONE transmitter (on the sending side) and ONE reciver (on the recieving side) then there's no 'return link' from reciever to sender for the reciever to 'acknowledge' anything.

    If that's not your situation, then that doesn't apply.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-03-28 16:42
    Hi, as allanlane5 suggests you will get better results if you have some kind of acknowledgement or synchronization between the two Stamps. One way you could do that is to have Stamp "A" continually transmit "x" until it receives confirmation that Stamp "B" has got the value you sent. The following piece of code might be what part of the Stamp "A" routine could look like.

    "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.
  • BeanBean Posts: 8,129
    edited 2008-03-28 18:15
    Here is the BS2 code from Parallax to do bi-directional communication with these:
    http://www.parallax.com/Portals/0/Downloads/sw/433RadioCRCV1.0.zip

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com

    ·
  • A KrishA Krish Posts: 27
    edited 2008-03-28 18:37
    Hi Jeff ...


    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 ...
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-03-28 18:46
    Hi, when you say garbage what actually are you receiving, is the "garbage" consistant. Is it possible the the baud value should be true and not inverted true=188 for 4800 baud rate. Can you give us the values that you are receiving at each end.

    Check out the code at Bean's link.

    Jeff T.
  • A KrishA Krish Posts: 27
    edited 2008-03-28 18:57
    Thanx Bean ... for the link ...
  • A KrishA Krish Posts: 27
    edited 2008-03-28 19:02
    No the garbage value is not consistent ... it varies diversely ...


    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
  • A KrishA Krish Posts: 27
    edited 2008-03-28 19:05
    BS2 "B"

    ' {$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
  • A KrishA Krish Posts: 27
    edited 2008-03-28 19:06
    Regarding the garbage value .. sometimes it doesnt even appear .. i mean its on and off .. I have placed the code that I am using above ... plzz check it out ..
  • Andy FoxAndy Fox Posts: 46
    edited 2008-03-28 21:49
    A couple suggestions from when I've learned experimenting with RF and the stamps:

    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?
  • A KrishA Krish Posts: 27
    edited 2008-03-29 17:46
    Guys .. Thanx a lot .. I really appreciate your efforts for helping me out .. Thanx a lot again ... I have been able to solve the problem ... The problem was that I was not using a delay at the receiver end ... once I did that ... I am well to go .. Once again thanx a lot for ur help ...
Sign In or Register to comment.