Shop OBEX P1 Docs P2 Docs Learn Events
simple question — Parallax Forums

simple question

computoncomputon Posts: 6
edited 2004-09-03 17:22 in BASIC Stamp
I have been using Basic Stamps, but never with values greater than a byte. Now, I need to use word values. I have two BS2s connected to RF transceivers, one acting as a transmitter, and one as a receiver, using the following code:

' transmit code
' {$STAMP BS2}
j VAR Word
Rx CON 13
TxFlow CON 14
Tx CON 15
N9600 CON $4054

loop:
FOR j = 0 TO 999
SEROUT Tx\TxFlow, N9600, [noparse][[/noparse]j]
PAUSE 100
DEBUG "just sent ", DEC3 j, CR
NEXT
GOTO loop


' receive code
' {$STAMP BS2}
value VAR Word
Rx CON 15
N9600 CON $4054
loop:
SERIN Rx, N9600, [noparse][[/noparse]value]
PAUSE 50
DEBUG "just received ",DEC3 value, CR
GOTO loop

So here's my question: how come the transmitter goes up to 999, but in the receiver's DEBUG window, it only goes up to 255 before going back to 0, and how do i fix this problem? (I realize 255 is max for byte.)

Thanks.

Comments

  • K de JongK de Jong Posts: 154
    edited 2004-09-03 17:19
    You may put a 'WAIT' into your Rx routine. Then you send the 'START' condition for the Rx and the bytes to be sent directly after that.

    Should work.

    Regards,

    Klaus
  • KenMKenM Posts: 657
    edited 2004-09-03 17:21
    Your basic stamp will handle a WORD variable.....(help file)



    The help file is your friend. I did not know the answers to your questions off the top of my head, so I opened my editor. After selecting BS2, I selected DEBUG_DEBUGIN.BS2 which shows the program example below.

    Then, HELP > INDEX > VAR explains the variable sizes.

    Hope this helps.

    ' DEBUG_DEBUGIN.BS2
    ' This program demonstrates the ability to accept user input from the
    ' Debug terminal, and to accept numeric entry in any valid format.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    myNum·········· VAR···· Word

    Main:
    · DO
    ··· DEBUG CLS, "Enter a any number: "·· ' prompt user
    ··· DEBUGIN SNUM myNum················· ' retrieve number in any format
    ··· DEBUG CRSRXY, 0, 2,················ ' display number in all formats
    ········· SDEC ? myNum,
    ········· SHEX ? myNum,
    ········· SBIN ? myNum
    ··· PAUSE 3000
    · LOOP································· ' do it again
    · END
  • Jeff MartinJeff Martin Posts: 755
    edited 2004-09-03 17:22
    Hi,

    The problem you are experiencing is due to the fact that the standard serial protocol is byte-oriented only.· The SEROUT and SERIN behave this was (in accordance with the protocol) but they will let you place a word-sized value in the brackets '[noparse]/noparse', however, the SEROUT command will only transmit the lower 8 bits of the value.· To get around this problem, you need to break the word-sized value into to bytes and send them one after the other, then receive them the same way on the other side.· There happens to be an easy way to do this (see code below):

    Transmit side:

    SEROUT Tx\TxFlow, N9600, [noparse][[/noparse]j.LOWBYTE, j.HIGHBYTE]

    Receive side:

    SERIN Rx, N9600, [noparse][[/noparse]value.LOWBYTE, value.HIGHBYTE]

    I think you realize the following, but just in case:
    Also, note that your DEBUG commands use the DEC3 formatter... this is fine for your example, but if you transmit a number over 999, you'll still only see the lowest three digits on the screen.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Jeff Martin

    · Sr. Software Engineer
    · Parallax, Inc.
Sign In or Register to comment.