sync code for Propeller
worthyamherst
Posts: 46
So im trying to get communication between a transmitter on a STAMP board to a receiver on a propeller board. I was wondering if there is a way to get the two to sync up with a start up pulse.
BS code:
and then on the propeller
BS code:
' TxCode_v_1.0.bs2 '{$STAMP BS2} '{$PBASIC 2.5} ' 'Parallax 433.92 MHz RF Receiver (#27981) Sample Tx Code (BS2) 'Connect Pin 8 of the BS2 to the DATA line on the RF module 'Connect +5v to the 5v line, connect Ground to the GND line 'This code will transmit two word sized counters, byte at a time. ' 'Note the PULSOUT instruction: this helps the receiver sync with 'the transmitter, especially after lapses in communication 'This code transmits at 9600 baud, inverted. x VAR Word y VAR Word DO PULSOUT 8, 1200 'Sync pulse for the receiver SEROUT 8, 16468, [ "!", x.HIGHBYTE, x.LOWBYTE, y.HIGHBYTE, y.LOWBYTE ] x = x + 1 y = y + 1 PAUSE 10 LOOP
and then on the propeller
CON 'ClkFreq: 80 Mhz _XINFREQ = 5_000_000 'Adjust the frequency _CLKMODE = XTAL1 + PLL16X 'Adjust the frequency rx = 0 tx = 1 baudRate = 9600 polarity = 1 bits = 8 OBJ bs : "BS2_Functions" 'Basic Stamp 2 library VAR byte number PUB start BS.start(31, 30) repeat number := BS.serin_char(rx, baudRate, polarity, bits) 'receive from BS; Tried to use "BS.serin_dec", but didn't work BS.serout_dec(30, number, baudRate, 1, 8) 'show data received on screen BS.Debug_char(13) waitcnt(clkfreq/2 + cnt) '0.5 sec pause
Comments
A good way to synchronize the receiver on the Propeller board is by using a "repeat until" statement. Consider the following Propeller Spin code:
With "ser" being an instantiation of some serial object (such as FullDuplexSerial or SimpleSerial) and val1, val2, and the ser.tx being something to do after the synchronization point. You can use the BS2 object and the serin/serout methods if you like - should work just the same .
On the Stamp side, I'd have something that looks like this:
Transmitting a hex $AA sends the bit pattern of 10101010 to the transmitter, effectively serving as the transmitter sync pulses. Synchronization of data happens with the transmission of "!". Actual data is sent after the "!".
Hope this helps
sorry for this, i'm not the most technologically savy.
Basically, I was just suggesting using FullDuplexSerial (or some other serial object) instead of the BS2 library for the Propeller. Take a look at the following code:
This code was written to get joystick data transmitted to the Propeller via an XBee wireless transceiver. Notice the "repeat until ser.rx == "U" in the main loop. That line instructs the Propeller to wait until it receives a "U" character from the receiving device. This has the effect of synchronizing the Propeller with the transmitter.