Shop OBEX P1 Docs P2 Docs Learn Events
sync code for Propeller — Parallax Forums

sync code for Propeller

worthyamherstworthyamherst Posts: 46
edited 2011-07-30 12:43 in Propeller 1
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:
' 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

  • Daniel HarrisDaniel Harris Posts: 207
    edited 2011-07-19 12:10
    Hello worthyamherst,

    A good way to synchronize the receiver on the Propeller board is by using a "repeat until" statement. Consider the following Propeller Spin code:
    repeat         'main loop
    
      repeat until ser.rx == "!"   'wait here until we get a "!" from the receiver  <-----synchronization point
    
      'do what you need done here, after the synchronization point
      val1 := ser.rx
      val2 := ser.rx
    
      ser.tx(val1 + val2)
    
    

    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:
    SEROUT 8, 16468, [ $AA, "!", x.HIGHBYTE, x.LOWBYTE, y.HIGHBYTE, y.LOWBYTE ]
    

    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 :D
  • worthyamherstworthyamherst Posts: 46
    edited 2011-07-19 12:50
    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 :).
    Ok im slightly confused on this so i woudl be replacing "ser" with...?
    sorry for this, i'm not the most technologically savy.
  • Daniel HarrisDaniel Harris Posts: 207
    edited 2011-07-30 12:43
    Hi worthyamherst,

    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:
    obj
    
      ser: "FullDuplexSerial"
    
    pub go | rx_ud, rx_lr
    
      ser.start(0, -1, 0, 9600)
    
      repeat
    
        repeat until ser.rx == "U"
       
        rx_ud := ser.rx          'up and down value received here
        rx_lr := ser.rx          'left and right value received here
    
    


    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.
Sign In or Register to comment.