Shop OBEX P1 Docs P2 Docs Learn Events
How to use SPSTR in basic stamp? — Parallax Forums

How to use SPSTR in basic stamp?

pathikgohil85pathikgohil85 Posts: 21
edited 2011-10-27 10:01 in BASIC Stamp
Hello Folks,

I am trying to use SPSTR in my programming. I want to know that how will I use it in SERIN statement and how do I read from SRAM?

Pathik Gohil

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-10-25 10:35
    If you don't have one, download a copy of the Basic Stamp Syntax and Reference Manual and look at the section on the SERIN statement and on the GET and PUT statements. Remember that these features depend on having a scratchpad RAM and this is found only on the BS2p/pe/px Stamps. I believe there's a discussion of SERIN and SPSTR on page 404.
  • pathikgohil85pathikgohil85 Posts: 21
    edited 2011-10-25 12:16
    Hi Mike,

    Thanks for reply. I did read about SPSTR on page 404 but that information is not clear to me. I am looking an example which explains me how will I implement in statement.

    Pathik Gohil
  • Mike GreenMike Green Posts: 23,101
    edited 2011-10-25 13:02
    To input a 5 character string into scratchpad locations 0-4, do:

    SERIN <pin>, <Baud>, [SPSTR 5]

    This can be included with other formatters to input numbers (DEC or HEX or BIN) or to wait for a specific string to appear (WAIT).

    The examples in the Manual under GET and PUT are pretty thorough.
  • pathikgohil85pathikgohil85 Posts: 21
    edited 2011-10-26 13:16
    So if My SERIN statement is below,

    SERIN 16,1,700,TIMO, [SPSTR 27]

    How will i read my contains from RAM?

    Should I run loop from 0-127 and use GET command?

    Pathik
  • Mike GreenMike Green Posts: 23,101
    edited 2011-10-26 13:59
    You have to use the GET statement. Whether you use a loop or just get specific characters from the string depends on the content of the string and what you want to do with it which you haven't discussed.
  • pathikgohil85pathikgohil85 Posts: 21
    edited 2011-10-26 14:12
    I am using SPSTR in my SERIN. It is going to to store my values in scratch pad ram from 0 to 28. Now I have to read them from scratch ram and assign them to individual decimal variables.

    Problem I am facing over here is, Using SPSTR will store my values in HEX. I want to store my values in variables in decimal.

    I hope that I made my problem statement clear.

    Pathik Gohil
  • Mike GreenMike Green Posts: 23,101
    edited 2011-10-26 14:22
    SPSTR will not store the characters in hex. It just stores them the way they come in from the serial device. Each location in scratchpad RAM just contains a character from the serial device. If those characters have any particular format, then you have to convert them yourself to what you need. If your device is providing characters "0"-"9" and "A"-"F" that represent hexadecimal values, then your conversion routine has to take that into account.
  • pathikgohil85pathikgohil85 Posts: 21
    edited 2011-10-26 15:00
    It is a string that I am sending through SPSTR.

    Example:

    RX/s0/s3/s, where /s stands for a blank space, it will be stored in the S-RAM as

    52
    58
    20
    30
    20
    33
    20

    52 stands for R
    58 for X
    20 for space
    30 for 0
    33 for 3

    These are ASCII values.

    I have to read them again in same manner.

    Pathik
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2011-10-26 15:06
    Pathik,

    As Mike said, if they come in that way (ASCII values), they will be read that way. The values do not change when stored in SPRAM. There are merely a sequence of bytes and you can store them into variables from the SPRAM. In what manner do you want them stored in variables?
  • pathikgohil85pathikgohil85 Posts: 21
    edited 2011-10-26 15:18
    oops My mistake Mike,

    Yes I got them. I am converting them in to Character before I send them. I am using LabView as GUI which converts them. When I read them, I want them in to decimal again.

    Pathik Gohil
  • Mike GreenMike Green Posts: 23,101
    edited 2011-10-26 17:34
    The other thread that you started has information on this sort of conversion (from scratchpad RAM).
  • pathikgohil85pathikgohil85 Posts: 21
    edited 2011-10-27 10:01
    Yes I figured out my problem. My labview was sending all variables to basic stamp in character strings. so I ran counter from 30 to 39 which are ascii values for 1 to 9. If I find a match then I ll subtract 30 out of it which gives me original value.

    Thanks a lot guys.
Sign In or Register to comment.