Shop OBEX P1 Docs P2 Docs Learn Events
Help on RS422 — Parallax Forums

Help on RS422

RichardFRichardF Posts: 168
edited 2008-04-12 17:42 in BASIC Stamp
I am·trying to learn·RS422 comms using two BS2SX-IC's connected by two LTC 490's. The following·are my super simple master and slave programs, which won't work!! Can anyone see why not?

' {$STAMP BS2sx}
' {$PBASIC 2.5}
'Master send RS422
TX PIN 12
RX PIN 13
HIGH TX
DO
· LOOP UNTIL RX = 1
PAUSE 1
SEROUT TX,18447,[noparse][[/noparse]"X"]
END

' {$STAMP BS2sx}
' {$PBASIC 2.5}
'Slave RS422
TX PIN 12
RX PIN 13
msgIn VAR Byte
DO
· LOOP UNTIL RX = 1
HIGH TX
SERIN RX,18447,[noparse][[/noparse]msgIn]
LOW TX
DEBUG msgIn
END

Thanks for the help,Richard

Comments

  • marzec309marzec309 Posts: 146
    edited 2008-04-11 21:59
    If you have two serial ports you can hook up both stamps. And debug both at the same time it might help but try this code its not tested though.

    Try this
    ' {$STAMP BS2sx}
    ' {$PBASIC 2.5}
    'Master send RS422
    TX PIN 12
    RX PIN 13
    Main:
      HIGH TX
      DO
        LOOP UNTIL RX = 1
        LOW TX
      PAUSE 10                       'changed from 1 to 10
      SEROUT TX,18447,[noparse][[/noparse]"X"]
      DEBUG "Sent"
      GOTO Main
    
    END
    
    
    



    ' {$STAMP BS2sx}
    ' {$PBASIC 2.5}
    'Slave RS422
    TX PIN 12
    RX PIN 13
    msgIn VAR Byte
    Main:
      DO
        LOOP UNTIL RX = 1
      HIGH TX
      PAUSE 15
      SERIN RX,18447,500,TimeOut,[noparse][[/noparse]msgIn]     'Wait for 1/2 sec for serial to start if it doesn't goto TimeOut
      LOW TX
      DEBUG ? msgIn
    END
    
    TimeOut:
      DEBUG "Serial Timed Out",CR,
            "Restarting",CR
      GOTO Main
    END
    
    
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-04-12 05:30
    First things first.·
    In neither of your listed programs have you any commands to execute·between the DO and the following LOOP,
    ' {$STAMP BS2sx}
    ' {$PBASIC 2.5}
    'Master send RS422
    TX PIN 12
    RX PIN 13
    HIGH TX
    [color=red]DO
      LOOP UNTIL RX = 1[/color]
    PAUSE 1
    SEROUT TX,18447,[noparse][[/noparse]"X"]
    END
    
    

    so it'll just dither that way until RX=1, where it'll serout once and END.· Marzec did it, too.· So, what gives?

    The first should be:
    ' {$STAMP BS2sx}
    ' {$PBASIC 2.5}
    
    'Master send RS422
    
    TX PIN 12
    RX PIN 13
    
    HIGH TX
    
    DO
     SEROUT TX,18447,[noparse][[/noparse]"X"]
     PAUSE 10
    
    LOOP UNTIL RX = 1
    
    END
    

    There's unfinished business, still.· You have RX Pin 13, but is it an input or an output?· [noparse][[/noparse]SEROUT takes care of TX, forcing it to be·an output.]
  • marzec309marzec309 Posts: 146
    edited 2008-04-12 17:42
    ·
    PJ Allen said...
    First things first.·
    In neither of your listed programs have you any commands to execute·between the DO and the following LOOP,
    ' {$STAMP BS2sx}
    ' {$PBASIC 2.5}
    'Master send RS422
    TX PIN 12
    RX PIN 13
    HIGH TX
    [color=red]DO
      LOOP UNTIL RX = 1[/color]
    PAUSE 1
    SEROUT TX,18447,[noparse][[/noparse]"X"]
    END
    
    

    so it'll just dither that way until RX=1, where it'll serout once and END.· Marzec did it, too.· So, what gives?

    The first should be:
    ' {$STAMP BS2sx}
    ' {$PBASIC 2.5}
    
    'Master send RS422
    
    TX PIN 12
    RX PIN 13
    
    HIGH TX
    
    DO
     SEROUT TX,18447,[noparse][[/noparse]"X"]
     PAUSE 10
    
    LOOP UNTIL RX = 1
    
    END
    

    There's unfinished business, still.· You have RX Pin 13, but is it an input or an output?· [noparse][[/noparse]SEROUT takes care of TX, forcing it to be·an output.]





    The reson I repeated that part of his program is because I believed he was using it as a program hold, and didn't want to completely rewrite his program. Basicaly wait for the other stamp to be ready then progress when it is.
Sign In or Register to comment.