Shop OBEX P1 Docs P2 Docs Learn Events
FullDuplexSerial "rx" Question — Parallax Forums

FullDuplexSerial "rx" Question

JMLStamp2pJMLStamp2p Posts: 259
edited 2008-01-25 19:29 in Propeller 1
Good Evening,
The code listed below works with a remote transciever transmitting the values "$01" and "$04". When I install the line··" repeat while rxbyte := (1)·" my LED "18"·toggles. If I change the line to "·repeat while rxbyte := (0)·" The LED stops toggling and my transmitter starts outputting "$01" &
"$04" as shown in the code below.

My Question is this:

I want to compare the number recieved by FullDuplexSerials "rx" Method
with a certain value and then jump to a method contingent upon what number is recieved. Could someone Please Edit the code below to help me
accomplish this.
Thanks,
JMLStamp2p
John.



............................................................................................

My Program Below:

............................................................................................

CON
·_CLKMODE = XTAL1 + PLL1X····· 'External crystal 5MHZ times "1"
·_CLKFREQ = 5_000_000········· '5 Million cycles per second

VAR
·byte rxbyte
·byte byte_recieved

OBJ
·DELAY: "Clock"
·DATA: "FullDuplexSerial"

..................................

PUB Main····
·················
·dira[noparse][[/noparse]0]~~
·dira[noparse][[/noparse]1]~
·dira[noparse][[/noparse]16]~~
·dira[noparse][[/noparse]17]~~
·dira[noparse][[/noparse]18]~~
·dira[noparse][[/noparse]20]~~
·'data.Stop
·data.start(1,0,2,9600)
·Recieve
·'Transmit

..........................................................................................

PUB Recieve
· data.rx······················· 'FullDuplexSerial recieve byte
·
· repeat while rxbyte := (1)······ 'Repeat while rxbyte is True or "1"
···· waitcnt(5_000_000 + cnt)
····· !outa[noparse][[/noparse]18]
······· waitcnt(5_000_000 + cnt)
· data.rxflush····················· ' Flush the recieve buffer
· Transmit·······

..........................................................................................
·
PUB Transmit
·waitcnt(5_000_000 + cnt)
·data.tx($01)
·waitcnt(5_000_000 + cnt)
·data.tx($04)
·Main
·

Comments

  • Gerry KeelyGerry Keely Posts: 75
    edited 2008-01-24 23:01
    repeat while rxbyte := (0)·-- you should use == to test for eqaulity not :=

    regards

    Gerry
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2008-01-24 23:42
    I understand as far as the·"==" goes, so are you saying that rxbyte holds the data that was recieved or do I have to read the buffer somehow ?

    JMLStamp2p.
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-25 00:44
    JMLStamp2p said...
    ... or do I have to read the buffer somehow ?
    Yes!

    Also, don't use inappropriate recursion!
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2008-01-25 13:09
    Could someone please give me an example of how this needs to be coded. Reading the FullDuplexSerial's buffer or lead me to some more information on how to interperate FullDuplexSerial. Thier doesn't seem to be alot of explanation of the code, I am·working my way through the Prop·manual.

    Thanks,
    JMLStamp2p
  • AribaAriba Posts: 2,685
    edited 2008-01-25 14:33
    A call to the rx methode of FullDuplexSerial returns the received byte:
    rxbyte := data.rx

    There are various methods:
    rx waits until a byte is received
    rxcheck returns immediatly with the received byte or -1 of nothing received
    rxtime is like rxcheck but waits some milliseconds for a byte.

    T send a byte call the tx methode:
    data.tx(txbyte)

    A Echo Loop:
    PUB echo  | rxbyte
      repeat
        rxbyte := data.rx
        data.tx(rxbyte)
        if rxbyte == 1       'compare with values
           ....
        if rxbyte == 2
          ...
        case rxbyte         'another compare methode
          3: .....
          4: .....
    
    



    Hope this helps

    Andy
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2008-01-25 15:01
    Andy,
    Thank You very much for posting this example. I will try this and if I have any questions I will reply.

    JMLStamp2p
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2008-01-25 19:29
    Andy,
    Everything is working fine, I can't thank you enough.
    It is greatly appreciated !
    JMLStamp2p
Sign In or Register to comment.