PDA

View Full Version : FullDuplexSerial "rx" Question



JMLStamp2p
01-25-2008, 05:13 AM
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[0]~~
·dira[1]~
·dira[16]~~
·dira[17]~~
·dira[18]~~
·dira[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[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
·

Gerry Keely
01-25-2008, 06:01 AM
repeat while rxbyte := (0)·-- you should use == to test for eqaulity not :=

regards

Gerry

JMLStamp2p
01-25-2008, 06:42 AM
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.

deSilva
01-25-2008, 07:44 AM
JMLStamp2p said...
... or do I have to read the buffer somehow ?

Yes!

Also, don't use inappropriate recursion!

JMLStamp2p
01-25-2008, 08:09 PM
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

Ariba
01-25-2008, 09:33 PM
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

JMLStamp2p
01-25-2008, 10:01 PM
Andy,
Thank You very much for posting this example. I will try this and if I have any questions I will reply.

JMLStamp2p

JMLStamp2p
01-26-2008, 02:29 AM
Andy,
Everything is working fine, I can't thank you enough.
It is greatly appreciated !
JMLStamp2p