Shop OBEX P1 Docs P2 Docs Learn Events
word sized vars' and serin/serout — Parallax Forums

word sized vars' and serin/serout

SteveDSteveD Posts: 64
edited 2005-10-15 23:26 in BASIC Stamp
I am using an rs-485 driver to send a word sized variable.· The following highlighted in red works, the master does display the number 7900 but I am sure there is a better way to get the job done.· While reading the stamp reference manual I noticed the Serin/Serout {Fpin} command but was not able to get this to work.· Could someone give me some pointers on cleaning up the·Serin/Serout portion of this code?· Would the Serin/Serout {Fpin} instruction not work in my application where a rs-485 driver is used?

Master

' {$STAMP BS2}
' {$PBASIC 2.5}
·
reply·· VAR Word
sio·· CON·· 8 'max.1&4
flo·· CON·· 9 'max.2&3
T2400 CON 396
id···· VAR··· Byte
again:
id = "A"
PAUSE 1000
HIGH flo: PAUSE 1
SEROUT sio,T2400,[noparse][[/noparse]id]
LOW flo
SERIN· sio,T2400,100,error,[noparse][[/noparse]reply.LOWBYTE]
SERIN· sio,T2400,100,error,[noparse][[/noparse]reply.HIGHBYTE]
DEBUG DEC reply,CR
GOTO again
error:
DEBUG "No Response",CR
GOTO again

Slave
·
' {$STAMP BS2}
' {$PBASIC 2.5}
myid· VAR Byte
sio·· CON·· 8 'max.1&4
flo·· CON·· 9 'max.2&3
T2400 CON 396
info· VAR Word
·
again:
myid = "A"
info = 7900
LOW flo
SERIN sio,T2400,[noparse][[/noparse]WAIT(myid)]
HIGH· flo: PAUSE 10
SEROUT· sio,T2400,[noparse][[/noparse]info.LOWBYTE]
SEROUT· sio,T2400,[noparse][[/noparse]info.HIGHBYTE]
GOTO again

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-15 23:22
    Sure, you can simplify like this:

    · SERIN Sio, T2400, 100, Error, [noparse][[/noparse]reply.LOWBYTE, reply.HIGHBYTE]

    Your program works because 2400 baud is pretty slow and the second SERIN can load between bytes -- but if you cranked up the speed at all you'd probably start missing that second byte.· By putting everything into one SERIN you're cool.· Of course, you can do the same thing with SEROUT.

    You need a second connection between devices to do flow control, so I don't think that will work in your case.· What you'll need to do is some sort of software protocol (kind of like you have now) to allow the master and slave to stay in sync.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax

    Post Edited (Jon Williams (Parallax)) : 10/15/2005 11:29:47 PM GMT
  • SteveDSteveD Posts: 64
    edited 2005-10-15 23:26
    Thank you!
Sign In or Register to comment.