Shop OBEX P1 Docs P2 Docs Learn Events
Serial Comunication Help (rs-485) — Parallax Forums

Serial Comunication Help (rs-485)

Andrew ParsonsAndrew Parsons Posts: 12
edited 2009-10-27 11:54 in BASIC Stamp
Hello all,


I am trying to get my stamps·talking through a rs-485 for my project ( please go to this post read about it if intrested http://forums.parallax.com/showthread.php?p=850046) in order to control a hb-25 montor contoller from my master via a pot. I have the two stamps comunicating but i am only able to recive/send one byte· of info and thus cannot transfer the proper RCtime from the pot to contol the variable pulsout from the slave stamp to the hb-25. here are my test prjoects that i am having problems with.

Master stamp
' {$STAMP BS2sx}
' {$PBASIC 2.5}
'
'========== Variables =============
reply VAR Byte ' Response from node.
xm_rcv CON 0 ' Pin 0 sets transmit (1) or receive (0).
serIO CON 1
time VAR Word ' rctime min value 1 max·value is 680 with currect setup
'========== Initialize ============
OUTPUT 0 'Make pin 0 an output
'========== Main Loop =============
loop1:
HIGH 7 'sets pin 7 high for cap charge
PAUSE 5 ' charge time
RCTIME 7, 1, time 'place decharge time in time var
HIGH 0 'Put the SN75176 into transmit mode
PAUSE 1 ' beathing room
SEROUT serIO,16468,[noparse][[/noparse]DEC time,"."]
LOW 0 'Put the SN75176 into rec mode
SERIN serIO,16468,100,error,[noparse][[/noparse]reply]
DEBUG HOME, "RC time = ", DEC5 time, " slave response =· ", reply
GOTO loop1
error:
DEBUG HOME, "communication error"
GOTO loop1




Now the slave project

' {$STAMP BS2sx}
' {$PBASIC 2.5}
time VAR Byte ' rc time from master
myid VAR Byte ' ID number to show communication is working
xm_rcv CON 0 ' Pin 0 sets transmit (1) or receive (0).
serIO CON 1 ' Pin 1 is used for serial input/output.
myId = "A" ' ID letter of this node.

again:
LOW xm_rcv ' Set 485 transceiver to receive mode.
SERIN serIO,16468,again, [noparse][[/noparse]time]
DEBUG HOME, "time = ", time
HIGH xm_rcv: PAUSE 10 ' Set 485 transceiver for transmit.
SEROUT serIO,16468, [noparse][[/noparse]myId] ' Send back my ID letter.
GOTO again ' Do it all over.




Thank you all in advance, the goal is to show the same value on the slaves time var as the master min 0001 max 00680 with current capacitor.

Comments

  • stamptrolstamptrol Posts: 1,731
    edited 2009-10-26 12:57
    You can send a word value over your '485 link by sending the two parts separately, like this: time.lowbyte, time.highbyte

    On the slave end, make time also a word variable.

    As nearly always is the case, using the WAIT modifier with SERIN will give infinitely better performance of any comm link with the Stamps.

    Cheers,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • Andrew ParsonsAndrew Parsons Posts: 12
    edited 2009-10-26 14:12
    stamptrol said...
    You can send a word value over your '485 link by sending the two parts separately, like this: time.lowbyte, time.highbyte

    On the slave end, make time also a word variable.

    As nearly always is the case, using the WAIT modifier with SERIN will give infinitely better performance of any comm link with the Stamps.

    Cheers,

    Could you please give an example with my code above, I have found serin and serout to be kinda hard to get working. I am greatful for your help.

    Andrew
  • stamptrolstamptrol Posts: 1,731
    edited 2009-10-26 14:47
    The Help files with the editor software discuss SERIN, SEROUT quite well.

    Away from the office at the moment, but assuming your code works:

    Master stamp
    ' {$STAMP BS2sx}
    ' {$PBASIC 2.5}
    '
    '========== Variables =============
    reply VAR Byte ' Response from node.
    xm_rcv CON 0 ' Pin 0 sets transmit (1) or receive (0).
    serIO CON 1
    time VAR Word ' rctime min value 1 max value is 680 with currect setup
    '========== Initialize ============
    OUTPUT 0 'Make pin 0 an output
    '========== Main Loop =============
    loop1:
    HIGH 7 'sets pin 7 high for cap charge
    PAUSE 5 ' charge time
    RCTIME 7, 1, time 'place decharge time in time var
    HIGH 0 'Put the SN75176 into transmit mode
    PAUSE 1 ' beathing room
    SEROUT serIO,16468,[noparse][[/noparse]"*",time.lowbyte,time.highbyte,"."] >>>>>>>>changes<<<<<<<
    LOW 0 'Put the SN75176 into rec mode
    SERIN serIO,16468,5000,error,[noparse][[/noparse]wait "#",reply] >>>>>>>changes<<<<<<<<<<
    DEBUG HOME, "RC time = ", DEC5 time, " slave response = ", reply
    GOTO loop1
    error:
    DEBUG HOME, "communication error"
    GOTO loop1




    Now the slave project

    ' {$STAMP BS2sx}
    ' {$PBASIC 2.5}
    time VAR Word ' rc time from master >>>>>>>>>>changes<<<<<<<<<
    myid VAR Byte ' ID number to show communication is working
    xm_rcv CON 0 ' Pin 0 sets transmit (1) or receive (0).
    serIO CON 1 ' Pin 1 is used for serial input/output.
    myId = "A" ' ID letter of this node.

    again:
    LOW xm_rcv ' Set 485 transceiver to receive mode.
    SERIN serIO,16468,5000,again, [noparse][[/noparse]wait "*", time.lowbyte,time.highbyte] >>>>>>>>changes<<<<<<<
    DEBUG HOME, "time = ", time
    HIGH xm_rcv: PAUSE 10 ' Set 485 transceiver for transmit.
    SEROUT serIO,16468, [noparse][[/noparse]"#",myId] ' Send back my ID letter. >>>>>>>>changes<<<<<<<<<
    GOTO again ' Do it all over.

    Cheers,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • Andrew ParsonsAndrew Parsons Posts: 12
    edited 2009-10-26 16:07
    I am at work as well, I want to thank you very much for your help and I will try the updated code the minute i get home and will post results. Again thank you.

    Andrew
  • Andrew ParsonsAndrew Parsons Posts: 12
    edited 2009-10-27 00:02
    Hello, I got back home and tried your updated code on the master and slave and was not able to get it working, it was complaning for brackets near the "*". any suggestions. Thanks in advance

    Andrew
  • Andrew ParsonsAndrew Parsons Posts: 12
    edited 2009-10-27 01:05
    Okay all I have managed to get this all working with some effort, but well worth it. Below is te master and slave program using an rs-485 serial driver.

    Any suggestions to clean up the code?

    'Working master with pot on master
    ' {$STAMP BS2sx}
    ' {$PBASIC 2.5}

    '========== Variables =============
    reply VAR Word
    time VAR Word ' rctime min value 1 max value is 680 with currect setup
    '========== Initialize ============
    OUTPUT 0 'Make pin 0 an output
    '========== Main Loop =============
    loop1:
    HIGH 7 ' charge capacitor
    PAUSE 5 ' charging
    RCTIME 7, 1, time 'discharge time
    HIGH 0 'Put the SN75176 into transmit mode
    PAUSE 1 ' beathing room
    SEROUT 1, 16624, [noparse][[/noparse]"B", DEC3 time, "A"]
    DEBUG HOME, DEC3 time
    GOTO loop1


    'slave with hb-25 connected to pin 15
    ' {$STAMP BS2sx}
    ' {$PBASIC 2.5}
    '
    [noparse][[/noparse] I/O Definitions ]

    HB25 PIN 15 ' I/O Pin For HB-25

    '
    [noparse][[/noparse] Variables ]
    time VAR Word ' rctime min value 1 max value is 680 with currect setup
    '
    [noparse][[/noparse] Initialization ]

    DO : LOOP UNTIL HB25 = 1 ' Wait For HB-25 Power Up
    LOW HB25 ' Make I/O Pin Output/Low
    PAUSE 5 ' Wait For HB-25 To Initialize
    PULSOUT HB25, 1875 ' Stop Motor 1
    OUTPUT 0 'Make pin 0 an output
    '
    [noparse][[/noparse] Program Code ]


    loop1:
    PAUSE 200
    LOW 0 'Put the SN75176 into rec mode
    PAUSE 1 ' beathing room
    SERIN 1, 16624, 500, error, [noparse][[/noparse]WAIT ("B"), DEC3 time]
    DEBUG HOME,DEC3 time
    PULSOUT HB25, 1875 + time
    GOTO loop1

    error:
    DEBUG HOME, "rec error"
    GOTO loop1
  • Andrew ParsonsAndrew Parsons Posts: 12
    edited 2009-10-27 01:06
    Thanks stamptrol·for your time and introducing me to the WAIT within serin command.
  • stamptrolstamptrol Posts: 1,731
    edited 2009-10-27 11:54
    Glad you were able to work through my forgetting the brackets!

    Cheers,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
Sign In or Register to comment.