Serial Comunication Help (rs-485)
Andrew Parsons
Posts: 12
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.
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
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
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
Andrew
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
Cheers,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·