Shop OBEX P1 Docs P2 Docs Learn Events
SEROUT and SERIN SPSTR question — Parallax Forums

SEROUT and SERIN SPSTR question

MoskogMoskog Posts: 554
edited 2009-02-21 18:59 in BASIC Stamp
Let's say I have these variables:

firstVar····· VAR Byte
secondVar· VAR Byte
thirdVar···· VAR Byte

Then I send them away with this command:

SEROUT TX, Baud, [noparse][[/noparse]firstVar, secondVar, thirdVar]

Now I want to receive them another place and put them directly into SPRAM,
like this:

SERIN RX, Baud, [noparse][[/noparse]SPSTR 24]

If all the 3 variables contains a number, like DEC 255 each, ·then the SPSTR should save a string of 24 "ones" from location 0.

But what if all three variables contains a number, let's say DEC 7, or %00000111?
Will the SEROUT command then send all the leading zeros or will the string be just·3X3 "ones", like 111111111 and then wait for next transmission to fill all the twentyfour bits?

Is there a way to format variables before SEROUT so the SPSTR-string will be exactly the lenght I want it to be? Example: I want to send·one word,·one byte and one nib and want to be sure the string contains 28 bits because I then want to read them from location 0,1,2 and 3 of the SPRAM.

Comments and helps will be appreciated!

Comments

  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-02-21 18:48
    SEROUT and SERIN always send and receive bytes (unless you use the 7 bit with parity mode). So when you send a word, a byte and a nib, you have to do it as
    [noparse][[/noparse]myword.byte0,myword.byte1,mybyte,mynib]
    and those will be sent as 4 bytes, and on the other end SPSTR 4 will end up with those 4 bytes in SPram locations 0 to 3. If you are doing this without flow control, be sure to keep the baud rate low enough.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • MoskogMoskog Posts: 554
    edited 2009-02-21 18:59
    OK, I see.. so a Nib will also be sent as a Byte without any further formatting. Now I also see I have misunderstood the SPSTR length format, should be in bytes, not bits as I thought. That explains a lot of confusion here!

    Thank you so much!!
Sign In or Register to comment.