Shop OBEX P1 Docs P2 Docs Learn Events
Transmit data between 2 propellers - please Help! — Parallax Forums

Transmit data between 2 propellers - please Help!

koze85koze85 Posts: 18
edited 2010-07-02 17:50 in Propeller 1
Hello, I have managed to setup 2 propellers running with the same configuration and from the same power output (Same Vss). The one collects data from various sensors and the other one must log them to a datalogger. I 've managed to make this two tasks work but i cannot connect the two propellers together so i can transmit the information between the propellers. I tried the fast inter-propeller object with no luck. Can i use a serial object to transmit decimal numbers and strings between the propellers? what is the simplest way to transmit data between 2 propellers? As far as i can understand i need to dedicate two pins in each propeller for rx tx communication and connect the first propeller tx pin to the second propeller rx and vice versa with 10k resistors for safety. Please help me i am a bit of desperate here because of university project that i have… I am a bit of newbie with propeller
Thanks in advance

Comments

  • AleAle Posts: 2,363
    edited 2010-07-02 06:25
    There are a number of ways, using FullDuplexSerial or a similar object and connecting tx->rx and rx->tx should work. series resistors are not needed and if you use them... 10 k is just too much. 100 or 150 ohm should suffice.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Visit some of my articles at Propeller Wiki:
    MATH on the propeller propeller.wikispaces.com/MATH
    pPropQL: propeller.wikispaces.com/pPropQL
    pPropQL020: propeller.wikispaces.com/pPropQL020
    OMU for the pPropQL/020 propeller.wikispaces.com/OMU
    pPropellerSim - A propeller simulator for ASM development sourceforge.net/projects/ppropellersim
  • koze85koze85 Posts: 18
    edited 2010-07-02 12:10
    ok so i will not use resistors suppose i connected two propellers in 14 and 15 pins rx tx for the one is tx rx for the other one
    then for the transmit propeller i use this code
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
     
    obj
    PST        :"Parallax Serial Terminal"
    Sub Transmit
    
    repeat
    PST.StartRxTx(14, 15, 0, 57600) 'Connect to the other propeller
    pst.Str(String("just a string")) 'send a string
    pst.Dec(123)                    'send a value
    

    and on the receiver this code

    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    VAR
    BYTE       dataBuffer[noparse][[/noparse]30]
    
    obj |sl
      PST   :       "Parallax Serial Terminal"
      text  :       "tv_text"
      F     :       "FloatMath"
      FS    :       "FloatString"
    
    Sub Receive
    text.start(20)                  'start tv object in pins 20,21,22,23
    
    PST.StartRxTx(15, 14, 0, 57600) 'Connect to the other propeller
    
    repeat
     
      text.str(FS.FloatToString(F.FFloat(pst.StrIn(databuffer)))) 'receive and show string
     
      text.str(FS.FloatToString(F.FFloat(pst.StrIn(pst.DecIn))))  'receive and show value
    

    Will this work or i am writing irrelevant things???
    thank you
  • koze85koze85 Posts: 18
    edited 2010-07-02 12:57
    Ok this code works fine, taken from Clock Loop post at http://forums.parallax.com/showthread.php?p=850318·for transmiting one byte but how can i transmit a decimal value or a string lets say "hello world" and 123.456
    transmit propeller
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    VAR
    BYTE       Fx[noparse][[/noparse]60]
    obj
    comm        :"FullDuplexSerialPlus"
    
    Pub Transmit |go, bpmstep
    
    comm.Start(14, 15, 0, 115200) 'Connect to the other propeller
    bpmstep:=123
     
    Repeat
      go := 0
      Comm.tx(213)                        'transmit sync number
        waitcnt(500 + cnt)              'wait for other prop to catch up
        Comm.tx(BpmStep)                 ' transmit BpmStep position
      waitcnt(500 + cnt)
      If Comm.rxtime(1) == 214
        Repeat go from 0 to 1000              ' get range of memory
          Fx[noparse][[/noparse]go] := Comm.rx
    


    and receiver propeller
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    VAR
    BYTE       Fx[noparse][[/noparse]60]
    obj
      comm        :"FullDuplexSerialPlus"
      text  :       "tv_text"
      F     :       "FloatMath"
      FS    :       "FloatString"
     
     
    Pub Receive |go, bpmstep
    text.start(20)                  'start tv object in pins 20,21,22,23
    
    comm.Start(15, 14, 0, 115200) 'Connect to the other propeller
    repeat
     go := 0
      If Comm.rxtime(1) == 213     'this looks for start number of 213
        BpmStep := Comm.rx        'then receives data and puts it in variable BpmStep
        text.str(FS.FloatToString(F.FFloat(Bpmstep)))
        waitcnt(5_000_000 + cnt)  '
        text.out($00)
      Comm.tx(214)           'this transmits for start number of 214
      Repeat go from 0 to 60        'this sets the range of memory locations I want to step through
        Comm.tx(Fx[noparse][[/noparse]go])     'this transmits that same memory range one byte at a time
        waitcnt(500 + cnt)  '1ms   'this waits 1ms to let receiver catch up.
     
      waitcnt(500_000 + cnt)
    

    ·
  • Mike GMike G Posts: 2,702
    edited 2010-07-02 13:00
    Your transmit code is not syntactically correct. This should work better.
    CON
        _clkmode = xtal1 + pll16x
        _xinfreq = 5_000_000
    
    VAR
      byte  command 
        
     
    obj
      PST        :"Parallax Serial Terminal"
    
    
    PUB Main
    
      PST.StartRxTx(31, 30, 0, 57600)
      waitcnt(cnt+clkfreq/8)
      
      repeat
        waitcnt(cnt + clkfreq/2) 
        pst.Str(String("just a string"))
        pst.NewLine 
        pst.Dec(123)
        pst.NewLine
    



    The Propeller receiver will need to parse the incoming string and determine the beginning and end of the data. For example, the code above transmits the following byte stream.
    6A 75 73 74 20 61 20 73 74 72 69 6E 67 0D 31 32 33 0D
    
    



    The "0x0D" marks the end of each data element.
    6A 75 73 74 20 61 20 73 74 72 69 6E 67 = just a string
    31 32 33 = 123

    This is basic serial communications and ASCII.
  • Mike GMike G Posts: 2,702
    edited 2010-07-02 13:06
    hello world <cr>
    123.456 <cr>

    68 65 6C 6C 6F 20 77 6F 72 6C 64 0D 31 32 33 2E 34 35 36 0D
    
    
  • koze85koze85 Posts: 18
    edited 2010-07-02 16:09
    Ok thanks all for replying i am very close now and i think it doesnt have much work now

    This is the code for the transmitter propeller

    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    VAR
    
    obj
    comm        :"FullDuplexSerialPlus"
      F     :       "FloatMath"
      FS    :       "FloatString"
    Pub Transmit |go, bpmstep
    
    comm.Start(14, 15, 0, 115200) 'Connect to the other propeller
     
     
    Repeat
     Comm.tx(214)
     Repeat go from 0 to 24        'this sets the range of memory locations I want to step through
        Comm.tx(Fx[noparse][[/noparse]go])     'this transmits that same memory range one byte at a time
        waitcnt(500 + cnt)  '1ms   'this waits 1ms to let receiver catch up.
     
    DAT
    
    FX byte "This is a line of text.",0
    

    And this for the receiver propeller with monitor
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    VAR
    word       Fx[noparse][[/noparse]24]
    obj
      comm        :"FullDuplexSerialPlus"
      text  :       "tv_text"
    Pub Receive |go
    text.start(20)                  'start tv object in pins 20,21,22,23
    comm.Start(15, 14, 0, 115200)   'Connect to the other propeller
    repeat
     If Comm.rxtime(1) == 214       'signal triger from the other propeller
      Repeat go from 0 to 24        'get range of memory 22 characters + terminating string
       Fx[noparse][[/noparse]go] := Comm.rx            'Set array of charactes in buffer
       Fx[noparse][[/noparse]23] :=$00                 'Terminate the string
     text.str(@Fx)            'Print the string
      waitcnt(5_000_000 + cnt)      'pause for a bit
      text.out($00)                 'erase the screen
    



    I do receive the screen but i can always display one character... Like this the code display the "T" character of the string.·If·instead of text.str(@fx) if i put text.str(@fx[noparse][[/noparse]1]) i will get the "h"

    What i should do to display the whole string??????
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2010-07-02 16:18
    I'm not sitting at a propeller to test this, but while not add this to your repeat loop?

    text.str(@fx[noparse][[/noparse]go])

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Feature Projects: PropellerPowered.com
    Visit the: PROPELLERPOWERED SIG forum kindly hosted by Savage Circuits.
  • koze85koze85 Posts: 18
    edited 2010-07-02 17:22
    Ok i found the error Fx must be declared as byte...

    everything is fine now for one string...When i try to send a second one only the second one shows up any ideas?
  • koze85koze85 Posts: 18
    edited 2010-07-02 17:50
    This is the code of the transmitter
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    VAR
    BYTE name1[noparse][[/noparse]25]
    BYTE name2[noparse][[/noparse]25]
    obj
    comm        :"FullDuplexSerialPlus"
    
    Pub Transmit |go, bpmstep,sl, string1,string2
    
    comm.Start(12, 13, 0, 115_200) 'Connect to the other propeller
     
     
    Repeat
     
     string1:=string("String1")
     string1:=string("String2")
    
     sl := STRSIZE(string1)
     Comm.tx(210)
     BYTEMOVE(@name1,string1,sl)
     Repeat go from 0 to 24        'this sets the range of memory locations I want to step through
        Comm.tx(name1[noparse][[/noparse]go])     'this transmits that same memory range one byte at a time
        waitcnt(500 + cnt)  '1ms   'this waits 1ms to let receiver catch up.
     
     sl := STRSIZE(string2)
     
     Comm.tx(211)
     BYTEMOVE(@name2,string2,sl)
     Repeat go from 0 to 5        'this sets the range of memory locations I want to step through
        Comm.tx(name2[noparse][[/noparse]go])     'this transmits that same memory range one byte at a time
        waitcnt(500 + cnt)  '1ms   'this waits 1ms to let receiver catch up.
    

    And this from the receiver
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    VAR
    byte       Fx[noparse][[/noparse]26]
    byte       Fx1[noparse][[/noparse]26]
    obj
      comm        :"FullDuplexSerialPlus"
      text  :       "tv_text"
    Pub Receive |go
    text.start(20)                  'start tv object in pins 20,21,22,23
    comm.Start(14, 15, 0, 115_200)   'Connect to the other propeller
    repeat
     
    
      If Comm.rxtime(1) == 210       'signal triger from the other propeller
       Repeat go from 0 to 22        'get range of memory 22 characters + terminating string
        Fx[noparse][[/noparse]go] := Comm.rx            'Set array of charactes in buffer
        Fx[noparse][[/noparse]25] :=$00
     
     go:=0
      If Comm.rxtime(1) == 211       'signal triger from the other propeller
       text.out($0D)
       Repeat go from 0 to 24        'get range of memory 22 characters + terminating string
        Fx1[noparse][[/noparse]go] := Comm.rx            'Set array of charactes in buffer
        Fx1[noparse][[/noparse]5] :=$00
                                     'Terminate the string
    
                                     'erase the screen
    
                                       'Terminate the string
     text.str(@Fx)                                          'Print the string
     text.str(@Fx1)
     
     
    
     waitcnt(5_000_000 + cnt)      'pause for a bit
      text.out($00)
    



    Screen only shows String2.... any ideas???

    ·
Sign In or Register to comment.