Shop OBEX P1 Docs P2 Docs Learn Events
Issues with SERIN — Parallax Forums

Issues with SERIN

GrantusGrantus Posts: 5
edited 2004-12-16 04:00 in BASIC Stamp
I am attempting to read in a serial packet that is being sent out from my computer program to the basic stamp....

The packet has a [noparse][[/noparse]HEAD],[noparse][[/noparse]COMMAND],[noparse][[/noparse]X],[noparse][[/noparse]Y],[noparse][[/noparse]TAIL]

Each part of this packet is a byte.

Head = 0x55 or ($55)
COMMAND = varies depending on command
etc..
Tail = 0xAA

No matter how i use the serin command in pbasic i alwarys seem to read in a hex value of like 7E or 7F????

I need to read in the serial message, if the first byte is a correct header then continue to read in the rest, check the tail, then perform the commands...

Is this possible with PBasic?

Grantus shakehead.gif

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-12-15 05:36
    Are the command, x, and y values individual bytes? If yes, you could do something like this:

    cmd    VAR   Byte
    xVal   VAR   Byte
    yVal   VAR   Byte
    tail   VAR   Byte 
     
    SERIN pin, baud, [noparse][[/noparse]WAIT($55), cmd\4]
    

    You could leave out the tail byte, but it will give you a way to double-check the packet.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office


    Post Edited (Jon Williams) : 12/15/2004 5:39:08 AM GMT
  • GrantusGrantus Posts: 5
    edited 2004-12-15 05:52
    Yeah they are all individual bytes ...
    Cheers, i will give that a go...

    Grantus
  • GrantusGrantus Posts: 5
    edited 2004-12-15 06:05
    This doesnt seem to help it just isnt reading in what i send down the serial port...
    I am using a program called "Serial Monitior" to check that my program is sending the correct data... and i believe that it is ...
    Something like 55 01 38 38 AA (55 header, 01 goto, x,y, AA tail)... and that seems correct.

    See i am trying to write a program that will make a camera mounted on 2 servos track certain objects.
    When the tracker finds something to lock onto it sends a GOTO command with a X and Y value to the stamp, which should then move my seros, and thus the camera....

    my code so far :

    ... some definitions up here ...

    pollLoop:

    TOGGLE LED
    SERIN Rpin, 9600,badData,2000,skipSerin,[noparse][[/noparse]WAIT(HEAD),sCommand,sXValue,sYValue,WAIT(TAIL)]
    TOGGLE LED
    DEBUG "-- Recieved Packet...",CR
    GOTO processPacekt 'process packet do the specified command

    ' If nothing is recieved then resart the loop.
    skipSerin:
    DEBUG "-- Nothing ...",CR
    GOTO pollLoop
    ' If bad data is recieved then resart the loop.
    badData:
    DEBUG "-- Parity Error ...",CR
    GOTO pollLoop

    GOTO pollLoop

    ... some other subroutines down here...
  • steve_bsteve_b Posts: 1,563
    edited 2004-12-15 11:50
    You don't say how you are 'viewing' your data with pbasic....

    I'm guessing a debug statement....
    You sure you have the declarations right?

    debug HEX xvalue· ??· or is it signed HEX (SHEX)?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·

    Steve
    http://members.rogers.com/steve.brady
    http://www.geocities.com/paulsopenstage

    "Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."

  • achilles03achilles03 Posts: 247
    edited 2004-12-15 12:20
    This doesn't really address your original problem, but you can take out the last part of your serin command:

    WAIT(TAIL)

    Once you've got the data you need, move on... unless you need that tailbyte?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2004-12-15 15:29
    One other thing...Are you sure you have the correct BAUD rate selected?· It says "9600" for the baud rate, but if you are trying to DO 9600 baud, that's not the correct number.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Knight Designs
    324 West Main Street
    P.O. Box 97
    Montour Falls, NY 14865
    (607) 535-6777

    Business Page:·· http://www.knightdesigns.com
    Personal Page:··· http://www.lightlink.com/dream/chris
    Designs Page:··· http://www.lightlink.com/dream/designs
    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-12-15 16:37
    The other thing to check is your mode -- is the data true or inverted?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • GrantusGrantus Posts: 5
    edited 2004-12-16 00:33
    Well, i have used DEBUG HEX sdata, or whatever the variable is, to view the data that is coming in...

    I have now taken the tail part out of the command...

    I am sure that the data is being transferred is using 9600 baud. But how does one "DO" a baud of 9600 in the serin statement?

    And im not sure whether the mode is true or inverted... how do i check this?

    Cheers for your quick responses turn.gif

    Grantus.
  • steve_bsteve_b Posts: 1,563
    edited 2004-12-16 00:59
    Well, if the data is coming from your PC, then it's inverted....
    (basically meaning that a digital 1 is represented by a -12V level in RS232; inversely, a digital 0 is represented by a +12V level).
    TRUE would be a straight digital 1 = +5volts and vise versa....this is good for uProc to uProc communication as you don't need an rs232 level shifter in there (less hardware).

    Look up the SERIN command in the Pbasic help file and it'll give a table with the values to use for your given needs.

    This is what you used:
    "SERIN Rpin, 9600,badData,2000,skipSerin,[noparse][[/noparse]WAIT(HEAD),sCommand,sXValue,sYValue,WAIT(TAIL)]"
    Using your value of 9600 equates to somewhere near 7bits at 800baud.
    So I wouldn't think it'd work!


    Anyhow, for a BS2 with 9600 N81 Inverted...you should use this:
    "SERIN Rpin, 16468,badData,2000,skipSerin,[noparse][[/noparse]WAIT(HEAD),sCommand,sXValue,sYValue,WAIT(TAIL)]"

    It's nice to use a constant at the beginning of your program:
    ie: N9600 con 16468
    So your code line should look like:
    "SERIN Rpin, N9600,badData,2000,skipSerin,[noparse][[/noparse]WAIT(HEAD),sCommand,sXValue,sYValue,WAIT(TAIL)]"
    (that'll at least get you started...don't know about your scommand and waits and all).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·

    Steve
    http://members.rogers.com/steve.brady
    http://www.geocities.com/paulsopenstage

    "Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."

  • GrantusGrantus Posts: 5
    edited 2004-12-16 01:45
    Cheeeers Dude. I will let you know if that all works!

    roll.gif

    Grantus
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-12-16 04:00
    The problem with using "magic numbers" (embedded numeric constants) is that you have to change them when you change BASIC Stamp modules. You might want to take advantage of conditional compilation and have a program that will let you change modules without recoding. The attached template has the most common baud rates included and will work with any BS2-family Stamp module.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
Sign In or Register to comment.