Shop OBEX P1 Docs P2 Docs Learn Events
Can I Use Scratch Pad RAM for Serin / Serout ? — Parallax Forums

Can I Use Scratch Pad RAM for Serin / Serout ?

I am using BS2P or BS2SX and I'm just plain out of Variable space.  My application has a 20 byte serial string.  I just stumbled onto SPSTR.  There is very little in my 2.2 Reference about SPSTR. 

Is there a more detailed description of how I might be able to use SPSTR in conjunction with Serin and Serout to free up some conventional variables in my programs?

Greg 

Comments

  • SapphireSapphire Posts: 496
    edited 2015-07-11 16:39
    You can use SPSTR to receive up to 127 bytes of data into SPRAM. The data will be placed starting at location 0. You can then read it out, byte at a time, using GET. If you know where in the data stream a particular piece of data is, you can just GET the appropriate byte(s). This should help save some RAM.
    There is no way to transmit data directly from SPRAM though.
    Note that SPSTR only works with the BS2p. Although the BS2sx has SPRAM, it does not support this formatter. 

  • Just to add to what Sapphire said,
    If you have a string in PUT/GET memory, you can output it with repeated GET/SEROUT commands.
    Variable space is a precious commodity in Stamps.  Two ways to conserve it are:
    1.  Make variables as small as you can.  Don't use a WORD where a BYTE will do, etc.2.  Re-use variables, but very carefully.
  • Greg,
    The SPSTR function will work as described above and does make large string grabs easier.
    The other thing I have done when the incoming string is repetitive is to use the SKIP parameter to grab successive chunks of the string and process the pieces separately on the fly.
        So, for example, if the incoming string is 100 characters and you only have variable room for 10, grab 10 bytes and process. Set SKIP to 10 and grab the next 10 characters on the next repeat of the incoming string. Process those data. Set SKIP to 20 and so on.
      It does take time, but many logging and control situations aren't that sensitive to a few seconds delay.
      Cheers,
  • If you have a string in PUT/GET memory, you can output it with repeated GET/SEROUT commands.

    This advice is worth some experimentation.  My application takes in 7 bytes, does some business with those bytes then does some other stuff like RCTIME, then sends out 20 Bytes.

    Its no problem using GET/PUT when I make up the data.  I am going to try using a series of 20 GET/SEROUT commands and see if the device getting the serial data still is happy.

    Great suggestion.

    Greg
Sign In or Register to comment.