Shop OBEX P1 Docs P2 Docs Learn Events
Need help for serial communication — Parallax Forums

Need help for serial communication

ArchiverArchiver Posts: 46,084
edited 2003-11-25 16:34 in General Discussion
I'm new with Stamps. My task is to send and receive 16 byte serial
data (telegram) to and from another control unit by serial
communication. First, building up the telegram according to the
prototype and send out. Then receive(read) the back telegram;
disassemble the telegram and make control.
I'm not sure of the code for getting data from
the SIN and send out data from SOUT. Could anyone help me on the
code? Thanks.

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-11-25 16:28
    Getting data from the DB9 (pin 1 and 2)

    MyBaud VAR 84 + 16384 ' 9600 baud, with Inversion
    SerData VAR WORD

    MAIN:
    SEROUT 16, MyBaud, [noparse][[/noparse]">",13]
    SERIN 16, MyBaud, [noparse][[/noparse]DEC SerData]
    SEROUT 16, MyBaud, [noparse][[/noparse]DEC SerData, 13]
    ' This will 'pend' until data arrives
    GOTO MAIN

    Use the 'terminal' window, set it to 9600 baud.
    Type in a number, then send with the 'enter' key.
    "16" here is NOT a 'real' pin, it indicates to
    the stamp to use the SIN/SOUT pins.





    --- In basicstamps@yahoogroups.com, "wangjin_68" <zy93@h...> wrote:
    > I'm new with Stamps. My task is to send and receive 16 byte serial
    > data (telegram) to and from another control unit by serial
    > communication. First, building up the telegram according to the
    > prototype and send out. Then receive(read) the back telegram;
    > disassemble the telegram and make control.
    > I'm not sure of the code for getting data from
    > the SIN and send out data from SOUT. Could anyone help me on the
    > code? Thanks.
  • ArchiverArchiver Posts: 46,084
    edited 2003-11-25 16:34
    In a message dated 11/25/2003 11:26:26 AM Eastern Standard Time,
    zy93@h... writes:


    > I'm new with Stamps. My task is to send and receive 16 byte serial
    > data (telegram) to and from another control unit by serial
    > communication. First, building up the telegram according to the
    > prototype and send out. Then receive(read) the back telegram;
    > disassemble the telegram and make control.
    > I'm not sure of the code for getting data from
    > the SIN and send out data from SOUT. Could anyone help me on the
    > code? Thanks.
    >

    If you want to set up serin to receive a string of bytes, you first have to
    have a byte array. For instance if you want to receive 4 bytes, you would
    define a variable:

    serstring var byte(4)

    This takes up 4 bytes of your available RAM.

    You would then write

    serin pin, baud, [noparse][[/noparse]STR serstring\4]

    You only have 26 bytes availbe for variable storage, so you would have to
    manage your variables very carefully.

    Serouting is no problem . All you have to do is write

    serout pin, baud [noparse][[/noparse]"This is a test message"], cr

    Receiving it is where the problem comes in. You can make your serstring a 16
    byte variable as long as you have RAM available. Be sure and use a delay
    when serouting so the serin has enough time to read the string.

    Sid Weaver
    W4EKQ
    Port Richey, FL


    [noparse][[/noparse]Non-text portions of this message have been removed]
Sign In or Register to comment.