Shop OBEX P1 Docs P2 Docs Learn Events
Urgently requires help on serial communications — Parallax Forums

Urgently requires help on serial communications

ArchiverArchiver Posts: 46,084
edited 2003-09-09 15:02 in General Discussion
I'm new with Stamps. My task is to get 7 bits of serial data from SIN
pin(2) from the DB9 of my BS2. After that this serial data will be
output into parallel form, with each bit at its desginated output
pin. This is my code. I'm not sure of the code for getting data from
the SIN. Could anyone help me on it? Thanks.


'{$STAMP BS2}
'{$PORT COM1}
'DirA,B,C,D each declares a group of 4 bits. DirA
encompasses bits 0-3, DirB encompasses bits 4-7.
'DirC encompasses bits 8-11, DirD encompasses bits 12-
15.

setup:
dirA=%1111 'Makes pin0-3 as output
dirB=%0001 'Makes pin4 as output


main:
Do
serin 15, 9600, aByte 'Serial input into 15 at baud 9600
outL=aByte 'Output each bit.
loop

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-09-07 06:36
    That's almost right, but... You need to define the variable

    abyte var byte

    and the syntax for the SERIN command requires square brackets around
    the data list, and a special code for 9600 baud, and reference to p16
    to use the pin 2 serial input::

    SERIN 16, $54, [noparse][[/noparse]aByte] 'Serial input into 15 at baud 9600

    There is online HELP with the IDE, and the Stamp manual (.pdf) is
    available from the Parallax web site.

    -- Tracy




    >I'm new with Stamps. My task is to get 7 bits of serial data from SIN
    >pin(2) from the DB9 of my BS2. After that this serial data will be
    >output into parallel form, with each bit at its desginated output
    >pin. This is my code. I'm not sure of the code for getting data from
    >the SIN. Could anyone help me on it? Thanks.
    >
    >
    >'{$STAMP BS2}
    >'{$PORT COM1}
    > 'DirA,B,C,D each declares a group of 4 bits. DirA
    >encompasses bits 0-3, DirB encompasses bits 4-7.
    > 'DirC encompasses bits 8-11, DirD encompasses bits 12-
    >15.
    >
    >setup:
    >dirA=%1111 'Makes pin0-3 as output
    >dirB=%0001 'Makes pin4 as output
    >
    >
    >main:
    >Do
    > serin 15, 9600, aByte 'Serial input into 15 at baud 9600
    > outL=aByte 'Output each bit.
    >loop
  • ArchiverArchiver Posts: 46,084
    edited 2003-09-07 15:13
    Tracy! Almost right -- port 16 has a 232 driver
    on it, so needs 'invert' mode. Thus:

    N9600 CON $54 ' 9600 baud selector
    I9600 CON N9600 + $4000 ' 'Invert' mode -- WITH driver
    AByte VAR BYTE

    SERIN 16, I9600, [noparse][[/noparse]AByte]
    ' Note, program will 'pend' at this entry, until
    ' a byte is received.

    ' Note the Stamp does NOT have predefined
    ' 'baud rate constants' -- you must look up the value
    ' you want in the table in the manual, and create your
    ' own 'baud rate constants' out of the entries there.
    ' Note the Stamp does 8-bit, No parity well, and
    ' 7-bit, even parity -- but that's it. The default
    ' is 8-bit, no parity.

    --- In basicstamps@yahoogroups.com, Tracy Allen <tracy@e...> wrote:
    > That's almost right, but... You need to define the variable
    >
    > abyte var byte
    >
    > and the syntax for the SERIN command requires square brackets
    around
    > the data list, and a special code for 9600 baud, and reference to
    p16
    > to use the pin 2 serial input::
    >
    > SERIN 16, $54, [noparse][[/noparse]aByte] 'Serial input into 15 at baud 9600
    >
    > There is online HELP with the IDE, and the Stamp manual (.pdf) is
    > available from the Parallax web site.
    >
    > -- Tracy
    >
    >
    >
    >
    > >I'm new with Stamps. My task is to get 7 bits of serial data from
    SIN
    > >pin(2) from the DB9 of my BS2. After that this serial data will be
    > >output into parallel form, with each bit at its desginated output
    > >pin. This is my code. I'm not sure of the code for getting data
    from
    > >the SIN. Could anyone help me on it? Thanks.
    > >
    > >
    > >'{$STAMP BS2}
    > >'{$PORT COM1}
    > > 'DirA,B,C,D each declares a group of 4 bits. DirA
    > >encompasses bits 0-3, DirB encompasses bits 4-7.
    > > 'DirC encompasses bits 8-11, DirD encompasses bits 12-
    > >15.
    > >
    > >setup:
    > >dirA=%1111 'Makes pin0-3 as output
    > >dirB=%0001 'Makes pin4 as output
    > >
    > >
    > >main:
    > >Do
    > > serin 15, 9600, aByte 'Serial input into 15 at baud 9600
    > > outL=aByte 'Output each bit.
    > >loop
  • ArchiverArchiver Posts: 46,084
    edited 2003-09-07 15:31
    Hi Allan,

    Port p16 inverts no matter whether you use $54 or $4054! It only
    matters if you are using flow control (SEROUT 16\15,...).

    Also...

    ---inverted mode rests low, goes high to send, and needs a pulldown
    resistor in open baudmode.


    --noninverted mode rests at a high level and goes low to send, and
    needs a pullup resistor in open baudmode.

    It is the second one, noninverted, $54, you would use if there is
    going to be an hardware inverter like the MAX232 in the interface to
    a standard RS232 line.

    -- Tracy



    >Tracy! Almost right -- port 16 has a 232 driver
    >on it, so needs 'invert' mode. Thus:
    >
    >N9600 CON $54 ' 9600 baud selector
    >I9600 CON N9600 + $4000 ' 'Invert' mode -- WITH driver
    >AByte VAR BYTE
    >
    >SERIN 16, I9600, [noparse][[/noparse]AByte]
    >' Note, program will 'pend' at this entry, until
    >' a byte is received.
    >
    >' Note the Stamp does NOT have predefined
    >' 'baud rate constants' -- you must look up the value
    >' you want in the table in the manual, and create your
    >' own 'baud rate constants' out of the entries there.
    >' Note the Stamp does 8-bit, No parity well, and
    >' 7-bit, even parity -- but that's it. The default
    >' is 8-bit, no parity.
    >
    >--- In basicstamps@yahoogroups.com, Tracy Allen <tracy@e...> wrote:
    >> That's almost right, but... You need to define the variable
    >>
    >> abyte var byte
    >>
    >> and the syntax for the SERIN command requires square brackets
    >around
    >> the data list, and a special code for 9600 baud, and reference to
    >p16
    >> to use the pin 2 serial input::
    >>
    >> SERIN 16, $54, [noparse][[/noparse]aByte] 'Serial input into 15 at baud 9600
    >>
    >> There is online HELP with the IDE, and the Stamp manual (.pdf) is
    >> available from the Parallax web site.
    >>
    >> -- Tracy
    >>
    >>
    >>
    >>
    >> >I'm new with Stamps. My task is to get 7 bits of serial data from
    >SIN
    >> >pin(2) from the DB9 of my BS2. After that this serial data will be
    >> >output into parallel form, with each bit at its desginated output
    >> >pin. This is my code. I'm not sure of the code for getting data
    >from
    >> >the SIN. Could anyone help me on it? Thanks.
    >> >
    >> >
    >> >'{$STAMP BS2}
    >> >'{$PORT COM1}
    >> > 'DirA,B,C,D each declares a group of 4 bits. DirA
    >> >encompasses bits 0-3, DirB encompasses bits 4-7.
    >> > 'DirC encompasses bits 8-11, DirD encompasses bits 12-
    >> >15.
    >> >
    >> >setup:
    >> >dirA=%1111 'Makes pin0-3 as output
    >> >dirB=%0001 'Makes pin4 as output
    >> >
    >> >
    >> >main:
    >> >Do
    >> > serin 15, 9600, aByte 'Serial input into 15 at baud 9600
    >> > outL=aByte 'Output each bit.
    >> >loop
    >
    >
    >To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    >from the same email address that you subscribed. Text in the
    >Subject and Body of the message will be ignored.
    >
    >
    >Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2003-09-07 15:50
    Correct, port p16 inverts no matter what.
    Therefore, if you use $54 by itself, you'll be
    sending stuff which looks inverted to other
    232 receivers -- like your PC. And
    vice-versa for receiving FROM your PC.

    That's why you have to use '+ $4000', so the
    BS2 will properly format the data, so when
    it goes through the inverting driver, it
    will look proper to your PC's receiver.

    These settings are what I use
    when using the P16 port. 232 is very
    forgiving, but I don't think your PC is
    THAT forgiving. I could be mistaken.

    If you're talking BS2 to BS2, then as long
    as they agree with each other you can use
    $54 on both sides.

    --- In basicstamps@yahoogroups.com, Tracy Allen <tracy@e...> wrote:
    > Hi Allan,
    >
    > Port p16 inverts no matter whether you use $54 or $4054! It only
    > matters if you are using flow control (SEROUT 16\15,...).
    >
    > Also...
    >
    > ---inverted mode rests low, goes high to send, and needs a pulldown
    > resistor in open baudmode.
    >
    >
    > --noninverted mode rests at a high level and goes low to send, and
    > needs a pullup resistor in open baudmode.
    >
    > It is the second one, noninverted, $54, you would use if there is
    > going to be an hardware inverter like the MAX232 in the interface
    to
    > a standard RS232 line.
    >
    > -- Tracy
    >
    >
    >
    > >Tracy! Almost right -- port 16 has a 232 driver
    > >on it, so needs 'invert' mode. Thus:
    > >
    > >N9600 CON $54 ' 9600 baud selector
    > >I9600 CON N9600 + $4000 ' 'Invert' mode -- WITH driver
    > >AByte VAR BYTE
    > >
    > >SERIN 16, I9600, [noparse][[/noparse]AByte]
    > >' Note, program will 'pend' at this entry, until
    > >' a byte is received.
    > >
    > >' Note the Stamp does NOT have predefined
    > >' 'baud rate constants' -- you must look up the value
    > >' you want in the table in the manual, and create your
    > >' own 'baud rate constants' out of the entries there.
    > >' Note the Stamp does 8-bit, No parity well, and
    > >' 7-bit, even parity -- but that's it. The default
    > >' is 8-bit, no parity.
    > >
    > >--- In basicstamps@yahoogroups.com, Tracy Allen <tracy@e...> wrote:
    > >> That's almost right, but... You need to define the variable
    > >>
    > >> abyte var byte
    > >>
    > >> and the syntax for the SERIN command requires square brackets
    > >around
    > >> the data list, and a special code for 9600 baud, and reference to
    > >p16
    > >> to use the pin 2 serial input::
    > >>
    > >> SERIN 16, $54, [noparse][[/noparse]aByte] 'Serial input into 15 at baud 9600
    > >>
    > >> There is online HELP with the IDE, and the Stamp manual (.pdf) is
    > >> available from the Parallax web site.
    > >>
    > >> -- Tracy
    > >>
    > >>
    > >>
    > >>
    > >> >I'm new with Stamps. My task is to get 7 bits of serial data
    from
    > >SIN
    > >> >pin(2) from the DB9 of my BS2. After that this serial data will
    be
    > >> >output into parallel form, with each bit at its desginated
    output
    > >> >pin. This is my code. I'm not sure of the code for getting data
    > >from
    > >> >the SIN. Could anyone help me on it? Thanks.
    > >> >
    > >> >
    > >> >'{$STAMP BS2}
    > >> >'{$PORT COM1}
    > >> > 'DirA,B,C,D each declares a group of 4 bits. DirA
    > >> >encompasses bits 0-3, DirB encompasses bits 4-7.
    > >> > 'DirC encompasses bits 8-11, DirD encompasses bits 12-
    > >> >15.
    > >> >
    > >> >setup:
    > >> >dirA=%1111 'Makes pin0-3 as output
    > >> >dirB=%0001 'Makes pin4 as output
    > >> >
    > >> >
    > >> >main:
    > >> >Do
    > >> > serin 15, 9600, aByte 'Serial input into 15 at baud 9600
    > >> > outL=aByte 'Output each bit.
    > >> >loop
    > >
    > >
    > >To UNSUBSCRIBE, just send mail to:
    > > basicstamps-unsubscribe@yahoogroups.com
    > >from the same email address that you subscribed. Text in the
    > >Subject and Body of the message will be ignored.
    > >
    > >
    > >Your use of Yahoo! Groups is subject to
    http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2003-09-09 14:15
    The SERIN X, X can be any input pins declare by the
    user right?

    N9600 CON $54, N9600 =no parity bit, CON=assign with,
    $54= ???? Anyone can enlighten me?

    What about I9600 CON N9600? I can't find what it
    means.

    AByte VAR BYTE, this statement ALONE will
    automatically receive data from an input X right? I
    know it can only hold 8 bits of data. Am I right?

    Sorry for the trouble. Thanks






    --- Allan Lane <allan.lane@h...> wrote:
    > Tracy! Almost right -- port 16 has a 232 driver
    > on it, so needs 'invert' mode. Thus:
    >
    > N9600 CON $54 ' 9600 baud selector
    > I9600 CON N9600 + $4000 ' 'Invert' mode -- WITH
    > driver
    > AByte VAR BYTE
    >
    > SERIN 16, I9600, [noparse][[/noparse]AByte]
    > ' Note, program will 'pend' at this entry, until
    > ' a byte is received.
    >
    > ' Note the Stamp does NOT have predefined
    > ' 'baud rate constants' -- you must look up the
    > value
    > ' you want in the table in the manual, and create
    > your
    > ' own 'baud rate constants' out of the entries
    > there.
    > ' Note the Stamp does 8-bit, No parity well, and
    > ' 7-bit, even parity -- but that's it. The default
    > ' is 8-bit, no parity.
    >
    > --- In basicstamps@yahoogroups.com, Tracy Allen
    > <tracy@e...> wrote:
    > > That's almost right, but... You need to define
    > the variable
    > >
    > > abyte var byte
    > >
    > > and the syntax for the SERIN command requires
    > square brackets
    > around
    > > the data list, and a special code for 9600 baud,
    > and reference to
    > p16
    > > to use the pin 2 serial input::
    > >
    > > SERIN 16, $54, [noparse][[/noparse]aByte] 'Serial input into 15 at
    > baud 9600
    > >
    > > There is online HELP with the IDE, and the Stamp
    > manual (.pdf) is
    > > available from the Parallax web site.
    > >
    > > -- Tracy
    > >
    > >
    > >
    > >
    > > >I'm new with Stamps. My task is to get 7 bits of
    > serial data from
    > SIN
    > > >pin(2) from the DB9 of my BS2. After that this
    > serial data will be
    > > >output into parallel form, with each bit at its
    > desginated output
    > > >pin. This is my code. I'm not sure of the code
    > for getting data
    > from
    > > >the SIN. Could anyone help me on it? Thanks.
    > > >
    > > >
    > > >'{$STAMP BS2}
    > > >'{$PORT COM1}
    > > > 'DirA,B,C,D each declares a group of 4 bits.
    > DirA
    > > >encompasses bits 0-3, DirB encompasses bits 4-7.
    > > > 'DirC encompasses bits 8-11, DirD encompasses
    > bits 12-
    > > >15.
    > > >
    > > >setup:
    > > >dirA=%1111 'Makes pin0-3 as output
    > > >dirB=%0001 'Makes pin4 as output
    > > >
    > > >
    > > >main:
    > > >Do
    > > > serin 15, 9600, aByte 'Serial input into 15 at
    > baud 9600
    > > > outL=aByte 'Output each bit.
    > > >loop
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed.
    > Text in the Subject and Body of the message will be
    > ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to
    > http://docs.yahoo.com/info/terms/
    >
    >

    __________________________________________________
    Do You Yahoo!?
    Play now and stand a chance to win cash prizes!
    http://yahoo.com.sg/millionaire
  • ArchiverArchiver Posts: 46,084
    edited 2003-09-09 15:02
    Well, I was doing several good Stamp techniques
    at the same time.

    The SERIN command is "SERIN 16, MyBaud, [noparse][[/noparse]MyByteVar]"

    1. The 'MyBaud' parameter is a baud rate divisor.
    See the Stamp manual 2.0c page 297 for a table of
    baud rate divisors.

    2. N9600 CON $54 (OR, N9600 CON 84)
    This creates a 'CONstant' which is replaced at
    compile time with the value. In this case,
    replaced with the 'baud rate divisor' of
    84 decimal, or $54 hexadecimal. This is the
    baud rate devisor of 9600 Baud for the BS2 and BS2e.

    3. I9600 CON N9600 + $4000
    This creates another 'constant' "I9600", which
    is replaced at runtime with the value $4054 hex, or
    16468 decimal. This value is the 'inverted' baud
    rate selector. 'Inverted' here is the BS2 term
    meaning "I have a 232 driver in circuit".
    Port 16 leads to the DB-9 connector to your PC,
    and HAS a 232 driver in circuit. If you used
    any other pin, you would need to add a 232 driver
    circuit (like a MAXIM-IC MAX232 chip) to get the
    232 levels. See other posts.

    4. SERIN receives data a BYTE at a time. There
    are MANY ways to put this byte into variables.
    See Manual 2.0c, pages 278 through 292. In the
    example, I merely put one byte directly into
    a BYTE variable, for your use later in the
    program.

    If you want something simple that works:
    MyByte VAR BYTE ' Declare 'MyByte' as a VARiable

    MAIN:
    SERIN 16, 16468, [noparse][[/noparse]MyByte] '
    SEROUT 16, 16468, [noparse][[/noparse]DEC MyByte]
    GOTO MAIN

    ' The additional 'CON' I define make changing the
    ' baud rates in the future much easier.

    --- In basicstamps@yahoogroups.com, Stanley Wong <barangsg@y...>
    wrote:
    > The SERIN X, X can be any input pins declare by the
    > user right?
    >
    > N9600 CON $54, N9600 =no parity bit, CON=assign with,
    > $54= ???? Anyone can enlighten me?
    >
    > What about I9600 CON N9600? I can't find what it
    > means.
    >
    > AByte VAR BYTE, this statement ALONE will
    > automatically receive data from an input X right? I
    > know it can only hold 8 bits of data. Am I right?
    >
    > Sorry for the trouble. Thanks
    >
    >
    >
    >
    >
    >
    > --- Allan Lane <allan.lane@h...> wrote:
    > > Tracy! Almost right -- port 16 has a 232 driver
    > > on it, so needs 'invert' mode. Thus:
    > >
    > > N9600 CON $54 ' 9600 baud selector
    > > I9600 CON N9600 + $4000 ' 'Invert' mode -- WITH
    > > driver
    > > AByte VAR BYTE
    > >
    > > SERIN 16, I9600, [noparse][[/noparse]AByte]
    > > ' Note, program will 'pend' at this entry, until
    > > ' a byte is received.
    > >
    > > ' Note the Stamp does NOT have predefined
    > > ' 'baud rate constants' -- you must look up the
    > > value
    > > ' you want in the table in the manual, and create
    > > your
    > > ' own 'baud rate constants' out of the entries
    > > there.
    > > ' Note the Stamp does 8-bit, No parity well, and
    > > ' 7-bit, even parity -- but that's it. The default
    > > ' is 8-bit, no parity.
    > >
    > > --- In basicstamps@yahoogroups.com, Tracy Allen
    > > <tracy@e...> wrote:
    > > > That's almost right, but... You need to define
    > > the variable
    > > >
    > > > abyte var byte
    > > >
    > > > and the syntax for the SERIN command requires
    > > square brackets
    > > around
    > > > the data list, and a special code for 9600 baud,
    > > and reference to
    > > p16
    > > > to use the pin 2 serial input::
    > > >
    > > > SERIN 16, $54, [noparse][[/noparse]aByte] 'Serial input into 15 at
    > > baud 9600
    > > >
    > > > There is online HELP with the IDE, and the Stamp
    > > manual (.pdf) is
    > > > available from the Parallax web site.
    > > >
    > > > -- Tracy
    > > >
    > > >
    > > >
    > > >
    > > > >I'm new with Stamps. My task is to get 7 bits of
    > > serial data from
    > > SIN
    > > > >pin(2) from the DB9 of my BS2. After that this
    > > serial data will be
    > > > >output into parallel form, with each bit at its
    > > desginated output
    > > > >pin. This is my code. I'm not sure of the code
    > > for getting data
    > > from
    > > > >the SIN. Could anyone help me on it? Thanks.
    > > > >
    > > > >
    > > > >'{$STAMP BS2}
    > > > >'{$PORT COM1}
    > > > > 'DirA,B,C,D each declares a group of 4 bits.
    > > DirA
    > > > >encompasses bits 0-3, DirB encompasses bits 4-7.
    > > > > 'DirC encompasses bits 8-11, DirD encompasses
    > > bits 12-
    > > > >15.
    > > > >
    > > > >setup:
    > > > >dirA=%1111 'Makes pin0-3 as output
    > > > >dirB=%0001 'Makes pin4 as output
    > > > >
    > > > >
    > > > >main:
    > > > >Do
    > > > > serin 15, 9600, aByte 'Serial input into 15 at
    > > baud 9600
    > > > > outL=aByte 'Output each bit.
    > > > >loop
    > >
    > >
    > > To UNSUBSCRIBE, just send mail to:
    > > basicstamps-unsubscribe@yahoogroups.com
    > > from the same email address that you subscribed.
    > > Text in the Subject and Body of the message will be
    > > ignored.
    > >
    > >
    > > Your use of Yahoo! Groups is subject to
    > > http://docs.yahoo.com/info/terms/
    > >
    > >
    >
    > __________________________________________________
    > Do You Yahoo!?
    > Play now and stand a chance to win cash prizes!
    > http://yahoo.com.sg/millionaire
Sign In or Register to comment.