Serial Communication over RF Transceivers
msoccer0607
Posts: 4
I'm somewhat new to basic stamp and am having problems sending data between two Parallax RF Transceivers. Here is the code I'm using for each transceiver:
Transmitter:
' {$STAMP BS2}
' {$PBASIC 2.5}
counter VAR Word
distance VAR Byte
rxd PIN 15
txflo PIN 13
txd PIN 14
distance = 20
FOR counter = 0 to 30
SEROUT txd\txflo, 84, [distance]
NEXT
Receiver:
' {$STAMP BS2}
' {$PBASIC 2.5}
counter VAR Word
distance VAR Byte
rxd PIN 4
txflo PIN 2
txd PIN 1
FOR counter = 0 TO 5
distance=0
DO WHILE (distance = 0)
SERIN rxd\txflo, 84, [distance(counter)]
LOOP
DEBUG DEC distance, CR
NEXT
Neither of these programs does anything. I'm just trying to use them to learn how to use RF communication. The problem I'm having is that I need to send distance 30 or more times just to get it 5 times at the receiver. I don't understand why that is being as I'm using flow control. Also, I have to have a "DO WHILE" loop around the SERIN otherwise SERIN reads a bunch of zeros and I get no useful data. I don't understand this either, but I'm assuming it has something to do with the transceivers. I would really appreciate it if someone could explain why I'm having these two problems!
Transmitter:
' {$STAMP BS2}
' {$PBASIC 2.5}
counter VAR Word
distance VAR Byte
rxd PIN 15
txflo PIN 13
txd PIN 14
distance = 20
FOR counter = 0 to 30
SEROUT txd\txflo, 84, [distance]
NEXT
Receiver:
' {$STAMP BS2}
' {$PBASIC 2.5}
counter VAR Word
distance VAR Byte
rxd PIN 4
txflo PIN 2
txd PIN 1
FOR counter = 0 TO 5
distance=0
DO WHILE (distance = 0)
SERIN rxd\txflo, 84, [distance(counter)]
LOOP
DEBUG DEC distance, CR
NEXT
Neither of these programs does anything. I'm just trying to use them to learn how to use RF communication. The problem I'm having is that I need to send distance 30 or more times just to get it 5 times at the receiver. I don't understand why that is being as I'm using flow control. Also, I have to have a "DO WHILE" loop around the SERIN otherwise SERIN reads a bunch of zeros and I get no useful data. I don't understand this either, but I'm assuming it has something to do with the transceivers. I would really appreciate it if someone could explain why I'm having these two problems!
Comments
I highly recommend that you take a look at the progamming examples in the 433 MHz RF Transceiver pdf-documentation:
http://www.parallax.com/Portals/0/Downloads/docs/prod/rf/27982-433MHzRFTransceiver-v1.1.pdf
If you still cant figure out how to solve your problems, please tell us!
Depending on the transceiver, you might need a "sync" pulse to properly activate the receiver. Also, you might need some error detection and correction. Some transceivers handle this themselves, many do not. Parallax provides sample code. If you can find the webstore page for the product, there's usually a link near the bottom of the page to documentation and sample code.
In your receive program, you do a SERIN using "distance(counter)". This assumes that "distance" is an array, yet you only declare "distance" as a single byte. PBasic does no checking and will just use the next several bytes as the array. You probably don't want the "(counter)" there.
If you purchased the RF Transceivers (Part#27988) then you can take advantage of this capability to send and
receive data in a robust, error checking, fashion. The disk or CD that accompanies the RF Transceivers contains
a number of source code examples for interfacing the RF Transceivers to two BASIC Stamp 2 modules..
I never seen these RF modules before either, who sold them to you? Do you have this CD? If you don't then somebody here at the forums might still keep it and can help with some source code examples. Or we can wait and see if anyone from Parallax steps in here with some good ideas.
[Switch mode is for reading switch status, Serial mode (conn to +5) is for sending data.]