27980 RF Transmitter Module
akash2345567
Posts: 3
Hello,
we having working sensors all from parallax and we have the transmitter working as well-
TABLE WAS SUPPOSED TO GO HERE
We use the code provided by parallax for both the sensors and transmitter
Thanks
we having working sensors all from parallax and we have the transmitter working as well-
TABLE WAS SUPPOSED TO GO HERE
We use the code provided by parallax for both the sensors and transmitter
Thanks
Comments
Have you looked at the sample code for the transmitter and receiver modules, particularly the one using CRC for error detection?
This sample code sends a text string and what you have is a series of byte or word values from the sensors. Instead of sending the text string, send the values you've gotten from the sensors instead. The sample code has a subroutine that calculates a CRC value which is then sent. It also sends a text string length before the text data (as described in the comments in the code). You can still send a length value that's the number of bytes you're sending, then you send the actual bytes, then the CRC value.
' =========================================================================
'
' File...... 433RadioTX.bs2
' Purpose... Demo code for the Parallax 433 MHz Transmitter (#27980)
' Author.... Parallax Inc.
' E-mail.... support@parallax.com
' Started...
' Updated... 01-17-2008
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' =========================================================================
'
[noparse][[/noparse] Program Description ]
' This code requires one Transmitter (#27980) and one Receiver (#27981).
' Each module should be connected to a separate BASIC Stamp 2 Module.
'
' This program is the transmitter side of the Parallax RF Transceiver
' Packet Transmission example. This code transmits the message in the DATA
' statements to the receiver.
'
' This code demonstrates the transmission and reception of variable-length
' data (from 1 to 16 bytes) in the form of data packets. This data packet
' method is used to help overcome the error-prone nature of RF reception in
' various environments. The data packets consist of a preamble, a count of
' the number of data bytes, the actual data bytes and finally a checksum
' value. The format is as follows:
'
' Preamble = "U!". Any number of "U" characters may be sent before the
' single "!". The "U" character is chosen because it's bit pattern is
' "10101010" (alternating 1's and zero's). This gets the receiver "in sync"
' with the data bits that follow.
'
' Packet data format:
' |
||
| |
||
||
|
' |Data Count||Data Value 1|...|Data Value n||Checksum Low||Checksum High|
' |
||
| |
||
||
|
' BYTE 1 BYTE 2 BYTE n+1 BYTE n+2 BYTE n+3
'
' Byte 1 consists of the Data Count. The Data Count is a value from 1 to 16
' representing the number of Data Values in this packet. Packets can
' contain from 1 to 16 bytes of data values (at least 1 Data Value is
' required).
' Byte 2 through Byte n+1 are the actual Data Values where
' n = Data Count+1.
' Byte n+2 and Byte n+3 are the last bytes in the packet and consist of a
' 16-bit Cyclic Redundancy Check (CRC) Checksum value calculated using the
' bytes 1 through n+1 together The use of this CRC checksum increases
' error detection to approx. 99%.
'
' The protocol for sending and receiving is as follows (shown is a
' simplified form):
' 1) The sending device constructs the entire packet, as shown above and
' calculates a checksum.
' 2) The sending device transmits the preamble and the packet.
' 3) The receiving device receives the packet, calculates a checksum and
' compares the calcuated checksum with the checksum received inside the
' packet.
' 4) If checksums match: receiver displays the recveived data, otherwise
' it displays a "receive error"
'
' Wiring:
' P15
Parallax 433 Transmitter Data (27980)
'
[noparse][[/noparse] Revision History ]
'
[noparse][[/noparse] I/O Definitions ]
Tx PIN 8 ' Transmitter (27981)DATA pin
'
[noparse][[/noparse] Constants ]
EOM CON 255 ' Value to signal end-of-message
#SELECT $STAMP ' Select Baud constants
#CASE BS2, BS2E, BS2PE
T1200 CON 813
T2400 CON 396
T4800 CON 188
T9600 CON 84
T19K2 CON 32
#CASE BS2SX, BS2P
T1200 CON 2063
T2400 CON 1021
T4800 CON 500
T9600 CON 240
T19K2 CON 110
#CASE BS2PX
T1200 CON 3313
T2400 CON 1646
T4800 CON 813
T9600 CON 396
T19K2 CON 188
#ENDSELECT
Inverted CON $4000 'Value for inverted serial format
Baud CON T9600+Inverted '9600 baud, 8,N,1 inverted
'
[noparse][[/noparse] Variables ]
string VAR Byte(16) 'Array to hold received data
idx VAR Word 'Index into message data
StrLen VAR Byte 'Length of string received
char VAR Byte 'Current character from message
cValue VAR Byte 'Holder for CRC calculation
crc VAR Word 'Calculate Crc value
'
[noparse][[/noparse] EEPROM Data ]
Message DATA "Akash"
DATA EOM
'
[noparse][[/noparse] Initialization ]
'
[noparse][[/noparse] Program Code ]
LOW Tx 'Initialize transceiver interface
DO
idx = Message 'Point idx to start of message data
DO
strLen = 0 'Set string length to zero
crc = 0 'Start Crc at zero
DO
strLen = strLen + 1
READ idx, char 'Read a character from message data
idx = idx + 1 'Point to next character in message
string(strLen-1) = char 'Put character into string array
cValue = char 'Prepare to add char to Crc value
GOSUB CalcCRC 'Add cValue to Crc value
IF (strLen = 15) OR (char = EOM) THEN EXIT 'Exit loop when ready
LOOP 'Keep reading message characters
' Send packet
PULSOUT Tx,1200 'Send sync pulse to radio
' Send preample "UUUU!", string length, string data, crc
SEROUT Tx, Baud, [noparse][[/noparse]"UUUU!", strLen, STR string\strLen,
crc.LOWBYTE, crc.HIGHBYTE]
PAUSE 100 'Give receiver time to process
LOOP WHILE char <> EOM 'Keep sending until EOM character
LOOP 'Start all over at the beginning
'
[noparse][[/noparse] Subroutines ]
' CRC Checksum Calculation Routine
CalcCRC:
CValue= crc.HIGHBYTE ^ cValue >> 4 ^ (crc.HIGHBYTE ^ cValue)
crc = cValue ^ (cValue << 5) ^ (cValue << 12) ^ (crc << 8)
RETURN
·
First you need to define what you want to send, what order it should be sent in, and how much data (8 bits or a 16 bit word) for each value.