Shop OBEX P1 Docs P2 Docs Learn Events
SERIN, WAIT and String or Constant — Parallax Forums

SERIN, WAIT and String or Constant

ArchiverArchiver Posts: 46,084
edited 2003-05-02 09:17 in General Discussion
HI:

I am using SERIN to wait for a certain Letter, the letter being "K"
before it can receive the rest of the transmission.

The code looks like this:

SERIN RX\FLO, I9600, 40, SENSOR, [noparse][[/noparse] WAIT ("Y"), DEC receiveVar]

IT waits 40 milliseconds for a "Y" to be sent from a trasmitter then
attains the number after the Y (receiveVar)and applies it to another
process. If it does not receive a Y in 40 milliseconds it goes to a
subroutine called SENSOR.


The problem that is happening is that I am sending a "Y"...the sender
shows its sending. But no matter what my receiver is not recognizing
the letter. PUtting STR for string to anything doesn't work either.
I've also testing using ASCII characters instead of Y but it has not
worked either.

Any suggestions?

Thanks,
Alison

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-05-01 21:46
    From your description, it could be that the "Y" is not being
    recognized as you say, or it could be that "Y" is seen and the
    problem is in receiving the variable data.

    Try this:

    SERIN RX\FLO, I9600, 40, SENSOR, [noparse][[/noparse] WAIT ("Y")]
    DEBUG "Got a Y"
    STOP

    If you see the DEBUG message, then the WAIT part is OK and try this:

    SERIN RX\FLO, I9600, 40, SENSOR, [noparse][[/noparse] WAIT ("Y"),receiveVar]
    DEBUG "Got ", HEX2 receiveVar

    (Note no DEC.) That will show you what followed the "Y".

    It may be that ending your SERIN argument list with DEC receiveVar is
    a problem. The DEC modifier tells SERIN to keep accepting ASCII
    numerics forever until something else appears. But in your case it's
    not clear that would ever happen, so the statement may be waiting
    patiently for more data before it passes control on to the next
    instruction.

    Regards,

    Steve
  • ArchiverArchiver Posts: 46,084
    edited 2003-05-01 23:39
    STeVE:

    Thank you. Right now it's not getting past the SERIN...

    SERIN RX\FLO, I9600, 40, SENSOR, [noparse][[/noparse]WAIT("Y"), receiveVar]
    HIGH 12

    I made a "HIGH 12" to turn on a light when if it passes the
    serin...it naver makes it past the serin.

    I also tried this:

    '''from transmitter
    SEROUT TX\FLO, BAUD, [noparse][[/noparse]"Y"]

    ''' receiver
    SERIN RX\FLO, BAUD, 40, SENSOR [noparse][[/noparse]WAIT("Y")]
    HIGH 12

    The above didn't work either. Any Thoughts?


    --- In basicstamps@yahoogroups.com, "S Parkis" <parkiss@e...> wrote:
    > From your description, it could be that the "Y" is not being
    > recognized as you say, or it could be that "Y" is seen and the
    > problem is in receiving the variable data.
    >
    > Try this:
    >
    > SERIN RX\FLO, I9600, 40, SENSOR, [noparse][[/noparse] WAIT ("Y")]
    > DEBUG "Got a Y"
    > STOP
    >
    > If you see the DEBUG message, then the WAIT part is OK and try this:
    >
    > SERIN RX\FLO, I9600, 40, SENSOR, [noparse][[/noparse] WAIT ("Y"),receiveVar]
    > DEBUG "Got ", HEX2 receiveVar
    >
    > (Note no DEC.) That will show you what followed the "Y".
    >
    > It may be that ending your SERIN argument list with DEC receiveVar
    is
    > a problem. The DEC modifier tells SERIN to keep accepting ASCII
    > numerics forever until something else appears. But in your case
    it's
    > not clear that would ever happen, so the statement may be waiting
    > patiently for more data before it passes control on to the next
    > instruction.
    >
    > Regards,
    >
    > Steve
  • ArchiverArchiver Posts: 46,084
    edited 2003-05-02 02:38
    You might want to make this as simple as possible at first and then
    add complexity:

    > '''from transmitter
    loop:
    DEBUG CR,"Sending"
    > SEROUT TX, BAUD, [noparse][[/noparse]"Y"]
    PAUSE 500
    GOTO loop

    > ''' receiver
    LOW 12
    loop:
    > OUT12 = 1 - OUT12
    > SERIN RX, BAUD, [noparse][[/noparse]WAIT("Y")]
    GOTO loop

    You should be able to see the data blips if you hook up your LED to
    the transmitter's TX pin. When you get that working, add the
    timeout and flow control features (one at a time) until you have
    everything working right.

    How have you defined TX, TX and BAUD and what models of Stamp are
    you using? Also, you mentioned in your first message that SENSOR is
    a subroutine. If by that you mean you exit that subroutine with a
    RETURN, that's another bug waiting to bite you, since the timeout is
    essentially a GOTO operation.

    How is the TX pin connected to the RX pin? Do the two Stamps share a
    common ground?

    Load your program up with DEBUG statements to see where you're
    going or not going. If all else fails, post your entire programs
    for review.

    Regards,

    Steve
  • ArchiverArchiver Posts: 46,084
    edited 2003-05-02 09:17
    Hi

    I think your problem is that the SERIN times out after just 40ms
    (no matter whether you use flow control or not).
    If your "Y" arrives shortly before execution of the SERIN or
    briefly after SERIN timed out (after 0.04s) it is just missed and
    your program continues with SENSOR (or whatever timeout target).
    As the stamp does not buffer serial IO, all characters get lost
    if they do not arrive exactly inside the SERIN read interval.

    I also believe that it is not the code that fails here, but rather
    the concept - you should probably redesign that part.
    Of course you could also "simply" add a buffer to that IO line.

    Regards
    Adrian
Sign In or Register to comment.