Shop OBEX P1 Docs P2 Docs Learn Events
Word capped out at 255? — Parallax Forums

Word capped out at 255?

weekdayhackweekdayhack Posts: 3
edited 2008-11-24 17:03 in BASIC Stamp
I am using the serin/serout commands to comminicate between two stamps.

I've pulled out the portion of my code that's giving me problems and I've simplified it to its lowest form (below and attached). I'm still having problems. I have an LCD and switch just for a sanity check. Everything operates as it should, but if I try to send "setpoint" from Stamp1 to Stamp2 with a value larger than 255, it just rolls it over. Not sure why I'm being capped at a Byte when I've declared "setpoint" as a Word. Probably has something to do with the fact that it's serial. Do I need to break the value up into managable pieces (size wise) using some mathematical operator in Stamp1 and then recombine them once they've reached Stamp2?·Seems strange to me that the serin/serout commands would be limited to·transferring just a Byte of data, but perhaps that makes sense given the serial is just 8-bit...???··Obviously clueless here. Any advice you can give is much appreciated.

-Neil

'Stamp1 (sends value)
' {$STAMP BS2px}
' {$PORT COM6}

· setpoint VAR Word
· setpoint=255
Send_value
· SEROUT 0\1,16468,[noparse][[/noparse]setpoint]
· GOTO Send_value··················· 'loop ensures that Stamp2 has a chance to recieve the value

'Stamp2 (recieves value)
' {$STAMP BS2px}
' {$PORT COM5}

· setpoint VAR Word
· btn7 VAR Bit
· SEROUT 14,188,[noparse][[/noparse]254,88] 'clear screen
· SEROUT 14,188,[noparse][[/noparse]254,71,20,4,254,75,254,84]'no cursor
button_enter:
· BUTTON 7,0,255,255,btn7,1,button_enter··········· 'allows me to make sure I can recieve the value when I·want it
· SEROUT 14,188,[noparse]/noparse]254,71,1,1,[color=red]"Setpoint="[/color············ 'just displaying it here instea of the debug window; obviously I get the same value both places
· GOTO Recieve_values
Recieve_values
· SERIN 0\1,16468, 50, Recieve_values, [noparse][[/noparse]setpoint]
· SEROUT 14,188,[noparse][[/noparse]254,71,1,2,DEC setpoint]
· GOTO Recieve_values································ 'loop ensures that I recieve the value if the timeout doesn't catch it for some reason

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-20 21:04
    SERIN and SEROUT handle byte values only. If you want to send a 16 bit value, you have to split it into two bytes or convert it to a stream of hexadecimal characters or a decimal digits, then convert it back at the other end. You could write:
    SEROUT 0\1,16468,[noparse][[/noparse]setpoint.lowbyte,setpoint.highbyte]

    and

    SERIN 0\1,16468,50,Recieve_values,[noparse][[/noparse]setpoint.lowbyte,setpoint.highbyte]
  • Carl HayesCarl Hayes Posts: 841
    edited 2008-11-20 21:08
    Serial communication in general is not limited to 8-bit bytes, but in practice the hardware is very often limited that way. This is the case with the SERIN and SEROUT commands, even when "receive" is spelled right. Note in the BS2 manual that all the constants given for specifying format are either 8-bits-no-parity or 7-bits-with-parity -- always 8 bits. The solution is fairly easy -- if you want to send a word-size datum, say SETPOINT, send it as two values, SETPOINT.BYTE0 and SETPOINT.BYTE1, and receive it at the other end the same way.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i
  • dandreaedandreae Posts: 1,375
    edited 2008-11-20 21:15
    Also on pages 89 to 91 of the BASIC Stamp Syntax and Reference Manual version 2.2 it will give you some examples and information regarding Aliases and modifiers.· Here is a· link for·the download of the manual:

    http://www.parallax.com/Store/Books/BASICStamp/tabid/168/CategoryID/42/List/0/Level/a/ProductID/143/Default.aspx?SortField=ProductName%2cProductName



    Dave



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dave Andreae

    Parallax Tech Support·
  • weekdayhackweekdayhack Posts: 3
    edited 2008-11-20 21:16
    thanks. it's now working. and next time I'll try to spell check my code [noparse]:)[/noparse]

    -Neil
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-11-20 22:55
    As a note the serial protocol itself is in fact byte oriented. All computers/modems etc. send data one byte at a time over stand modems and serial interfaces. This is not a limitation of the BASIC Stamp. The most common format is 8-N-1…adding the start bit and you have 10 bits per byte. As mentioned above 16-bit data is simply sent as two 8-bit values.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • Carl HayesCarl Hayes Posts: 841
    edited 2008-11-20 23:43
    Chris is right -- the eight-bit convention is nearly universal nowadays, for asynch anyway. It would be easy, though pointless, to program around it and do everything in software (rather than firmware) at both ends. Then you could send data in chunks of any size you like.

    Eight bits is not universal, and did not come first. Few people use Baudot nowadays, but some do -- and Baudot is a five-bit convention (plus start and stop bits), and was once extremely common (like my across-the-street neighbors,·about the most common people I've ever had the misfortune to meet). I imagine there have been other conventionss, of different lengths.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i

    Post Edited (Carl Hayes) : 11/20/2008 11:48:42 PM GMT
  • davejamesdavejames Posts: 4,047
    edited 2008-11-21 00:32
    ..whoa, whoa, whoa!!!!!!!!!!!!

    $PORT?!?!· You mean you can specify which COM port the BS2 will use for SERIN/SEROUT?

    And here I've been scrambling about for the last few days pestering all sorts of people with how to do this and IT'S IN THE BOOK?!

    AAARRRRGGGHHHHHHH!!!!!!!!!!!!!!!!!!!!!!!!

    (breathe Dave, breath....)
    I'm better now.

    OK - before I go running off to check this out, does this directive work when there's a USB adapter sitting between the BOE serial port and the PC's USB port?

    DJ




    Post Edited (davejames) : 11/21/2008 12:46:47 AM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-21 00:58
    You have to specify the I/O pin number(s) in the SERIN / SEROUT statement. As a result, you can specify any of the I/O pins including pin #16 which isn't really an I/O pin, but refers to the programming port used to download from a PC and used for the DEBUG / DEBUGIN statements. (It's not a directive)· Take a deep·breath and read the manual.

    The Stamp has no idea whether a USB adapter is present or not. All it knows is that there is supposed to be a logic level serial port. There's circuitry on the Stamp module to allow direct connection of the programming port to an RS232 serial port (or USB to RS232 adapter).
  • Carl HayesCarl Hayes Posts: 841
    edited 2008-11-21 01:05
    No, Davejames, you can't specify which "port" the BS2 will use for SERIN and SEROUT.· You can specify which pin, or·pins, it will use, though.· In the BS2, the word "port" has little meaning.· Whichever pins you use for SERIN and SEROUT constitute a serial port, I guess.

    The $PORT directive specifies which port on the PC your Stamp is attached to.· Many PCs have multiple serial ports, and you might attach a Stamp to any, or all.· The PC I'm writing this on has Stamps on COM1, COM2, and COM5 at the moment.· Use $PORT to say which Stamp to download to.· If there's no $PORT directive, the Editor will ask which one.· That's all.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i
  • weekdayhackweekdayhack Posts: 3
    edited 2008-11-21 01:08
    I just use this to specify which stamp receives the programming through my usb-to-serial adaptor.

    It's quite convenient to do this when programming multiple stamps on a single board, with the alternative being unplugging and reconnecting the serial cable to the other connector on the board...and then back and forth in an endless loop of rs232 loathing.

    -Neil
  • davejamesdavejames Posts: 4,047
    edited 2008-11-21 16:32
    Neil/Carl/Mr. Green,

    (an excerpt from a recent email to Jeff Martin, a very patient Parallax apps guy):

    "...I am beginning to believe that my requirement has turned into a classic case of knowing how to ask the right question and RTM (read-the-manual)."

    I did not see the $PORT directive until yesterday, so I had no idea which COM port to use in my application. That question drove me down the bunny-trails of attempting to reprogram the FTDI VCP to writing my own "Stamp-present" detection routine.

    So, now I know - and knowing is half the battle (GO JOE!).

    A big lesson learned is asking the right question. If I had done that, you all would have pointed me to $PORT a week ago relieving me of a ton-o-confusion.

    Thanks much,

    DJ
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-11-24 16:00
    DJ,

    Perhaps I missed something somewhere…the $PORT directive is useful for one thing really…if you have multiple serial ports and you don’t want the BASIC Stamp Editor checking them all for a BASIC Stamp when programming. It’s really useful if you have multiple BASIC Stamps connected to the PC, for example when testing RF Modules and one has TX code and the other has RX code. You can specify the TX code to go right to the TX board instead of prompting you. It doesn’t affect inability to program a BASIC Stamp or not find one, unless the directive exists for a port which the BASIC Stamp is not on. Perhaps I missed the underlying issue.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • davejamesdavejames Posts: 4,047
    edited 2008-11-24 17:03
    Hi Mr. Savage,

    Again, my situation has been a combination of me not understanding the technical issues of what I need to do, me not asking the right questions, me not understanding what the Stamp Reference manual is saying, and so on, and so on.

    I had a Friday afternoon discussion with Mr. Martin (very nice internal Parallax software guy), which has clarified my need and the steps to achieve it. Evidently I'm one of a small number of people that have this particular requirement.

    So, yes, I now understand the use of $PORT and how it will not help my efforts. Mr. Martin has pointed me to, and sent some info that discusses COM port detection. Mr. Pilgrim has also made a potentially useful suggestion.

    I'm standing down from pestering everybody for a few days until I can read through Mr. Martin's material and formulate more focused questions.

    Thanks for your input.

    Happy Thanksgiving everyone,

    DJ
Sign In or Register to comment.