Shop OBEX P1 Docs P2 Docs Learn Events
PC Serial Port Flow Control — Parallax Forums

PC Serial Port Flow Control

ArchiverArchiver Posts: 46,084
edited 2004-04-26 22:53 in General Discussion
Confused about doing serial i/o through serial port to PC, via the
serin/serout pins. Not sure how to handle flow control and I've read
contradictory info (or so it seems).

I will be sending data in both directions and don't want to miss any
bytes. Don't want xon/xoff software bytes in the stream because I will
be sending binary data and don't want to handle escape sequences (messy).

I am writing the PC comm software (Java), so I can set whatever
options I need to. I see that I can connect DSR to DTR and RTS to CTS.
This makes the PC see hardware flow control? Or is this faked (e.g. no
real flow control)?

I imagine the PC has buffer space so sending to it is not too bad. But
from the PC to Stamp (BS2), how is it effectively throttled? My stamp
will have other duties so I think flow control is essential.

I am not an electronics person and fairly new to Stamps, but I've read
a ton of stuff so far. Stamp-Stamp serial comm. seems easier with the
explicit flow control pin.

Thanks for any help.

Harry

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2004-04-26 06:32
    Harry-

    Here's one approach that works. First and foremost, the PC never
    sends the Stamp anything until the Stamp prompts the PC for data by
    sending a code or command of some kind, and the Stamp doesn't send
    that code or command until it is prepared to receive data (SERIN
    follows immediately). Second, the PC waits a few msec before
    actually transmitting data in response to the code/command from the
    Stamp. Going the other direction, the serial port's buffer and the
    PC's speed usually take care of data flowing from the Stamp to the
    PC.

    Regards,

    Steve

    On 25 Apr 04 at 22:54, harrybstoner wrote:

    > Confused about doing serial i/o through serial port to PC, via the
    > serin/serout pins. Not sure how to handle flow control and I've read
    > contradictory info (or so it seems)...
  • ArchiverArchiver Posts: 46,084
    edited 2004-04-26 08:34
    Supposing you have the following connections:
    *PC* *Stamp*
    RTS from PC --> 27kohm resistor to p1 on Stamp
    CTS on PC <-- 220 ohm p0 on Stamp
    TX from PC --> Sin on Stamp (p16)
    RX on PC <-- Sout on Stamp (p16)
    COM --- COM

    On the Stamp, use a command like this...
    SERIN 16\0,$4054,6000,bailout,[noparse][[/noparse]zork]
    The Stamp will hold p0 at a low level until it is ready to receive,
    and the PC must look at its CTS line (Clear to Send), and wait up
    until that line goes high before sending a byte to the Stamp.

    The Stamp output looks like this:
    serout 16\1,$4054,60000,bailout,[noparse][[/noparse]"A"]
    The Stamp will only transmit when its p1 input (from the PC RTS line)
    is high. So the PC should keep that line high unless it wants the
    Stamp to hold off on sending it data. As you noted, that will not
    usually be a problem unless there is danger of overrunning the PC
    buffer.

    If necessary, pace the transmission on the PC end to give time for
    the Stamp to react. Some PCs have a transmit buffer that might not
    react to the flow control signal from the Stamp on a byte to byte
    basis.

    If you use an inverting buffer like the MAX232 on the CTS/RST lines,
    then the baudmode parameters become $54 for non-inverted, instead of
    $4054 as written above. You could use the DTR/DSR pair, instead of
    RTS/CTS, if that is more convenient.

    -- Tracy




    >I am writing the PC comm software (Java), so I can set whatever
    >options I need to. I see that I can connect DSR to DTR and RTS to CTS.
    >This makes the PC see hardware flow control? Or is this faked (e.g. no
    >real flow control)?
    >
    >I imagine the PC has buffer space so sending to it is not too bad. But
    >from the PC to Stamp (BS2), how is it effectively throttled? My stamp
    >will have other duties so I think flow control is essential.
    >
    >I am not an electronics person and fairly new to Stamps, but I've read
    >a ton of stuff so far. Stamp-Stamp serial comm. seems easier with the
    >explicit flow control pin.
  • ArchiverArchiver Posts: 46,084
    edited 2004-04-26 13:06
    There are lots of good ways for you to do serial i/o with a Basic Stamp 2.
    However, there is also a Javelin Stamp. The Javelin Stamp has a feature
    called 'Virtual Peripherals'. From a programming point of view, a Virtual
    Peripheral UART is like having a serial i/o input buffer. The VP UART has
    methods: byteAvailabl( ) and receiveByte( ).

    ________


    Original Message
    From: "harrybstoner" <tedstoner@1...>
    To: <basicstamps@yahoogroups.com>
    Sent: Sunday, April 25, 2004 6:54 PM
    Subject: [noparse][[/noparse]basicstamps] PC Serial Port Flow Control


    > Confused about doing serial i/o through serial port to PC, via the
    > serin/serout pins. Not sure how to handle flow control and I've read
    > contradictory info (or so it seems).
    >
    > I will be sending data in both directions and don't want to miss any
    > bytes. Don't want xon/xoff software bytes in the stream because I will
    > be sending binary data and don't want to handle escape sequences (messy).
    >
    > I am writing the PC comm software (Java), so I can set whatever
    > options I need to. I see that I can connect DSR to DTR and RTS to CTS.
    > This makes the PC see hardware flow control? Or is this faked (e.g. no
    > real flow control)?
    >
    > I imagine the PC has buffer space so sending to it is not too bad. But
    > from the PC to Stamp (BS2), how is it effectively throttled? My stamp
    > will have other duties so I think flow control is essential.
    >
    > I am not an electronics person and fairly new to Stamps, but I've read
    > a ton of stuff so far. Stamp-Stamp serial comm. seems easier with the
    > explicit flow control pin.
    >
    > Thanks for any help.
    >
    > Harry
    >
    >
    >
    >
    > 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.
    >
    > Yahoo! Groups Links
    >
    >
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2004-04-26 13:47
    This article shows how to do flow-control serial comms with a PC using
    VB; it should be helpful:

    http://www.parallax.com/dl/docs/cols/nv/vol3/col/nv89.pdf

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


    Original Message
    From: harrybstoner [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=2hNeNI0oBq7WBtki9vA7TWrzlnPFjnhdCnyL--C9vk9pRwrVbct73ZaxpGcREnmrdls2T4N5pZuYRoRZ]tedstoner@1...[/url
    Sent: Sunday, April 25, 2004 5:55 PM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] PC Serial Port Flow Control


    Confused about doing serial i/o through serial port to PC, via the
    serin/serout pins. Not sure how to handle flow control and I've read
    contradictory info (or so it seems).

    I will be sending data in both directions and don't want to miss any
    bytes. Don't want xon/xoff software bytes in the stream because I will
    be sending binary data and don't want to handle escape sequences
    (messy).

    I am writing the PC comm software (Java), so I can set whatever options
    I need to. I see that I can connect DSR to DTR and RTS to CTS. This
    makes the PC see hardware flow control? Or is this faked (e.g. no real
    flow control)?

    I imagine the PC has buffer space so sending to it is not too bad. But
    from the PC to Stamp (BS2), how is it effectively throttled? My stamp
    will have other duties so I think flow control is essential.

    I am not an electronics person and fairly new to Stamps, but I've read a
    ton of stuff so far. Stamp-Stamp serial comm. seems easier with the
    explicit flow control pin.

    Thanks for any help.

    Harry
  • ArchiverArchiver Posts: 46,084
    edited 2004-04-26 14:13
    I don't think the BS2 can drive the CTS signal
    back to the PC -- you MUST have a MAX232 or
    equivalent for that line. The other lines look
    correct, though.

    --- In basicstamps@yahoogroups.com, Tracy Allen <tracy@e...> wrote:
    > Supposing you have the following connections:
    > *PC* *Stamp*
    > RTS from PC --> 27kohm resistor to p1 on Stamp
    > CTS on PC <-- 220 ohm p0 on Stamp
    > TX from PC --> Sin on Stamp (p16)
    > RX on PC <-- Sout on Stamp (p16)
    > COM --- COM
    >
    > On the Stamp, use a command like this...
    > SERIN 16\0,$4054,6000,bailout,[noparse][[/noparse]zork]
    > The Stamp will hold p0 at a low level until it is ready to receive,
    > and the PC must look at its CTS line (Clear to Send), and wait up
    > until that line goes high before sending a byte to the Stamp.
    >
    > The Stamp output looks like this:
    > serout 16\1,$4054,60000,bailout,[noparse][[/noparse]"A"]
    > The Stamp will only transmit when its p1 input (from the PC RTS
    line)
    > is high. So the PC should keep that line high unless it wants the
    > Stamp to hold off on sending it data. As you noted, that will not
    > usually be a problem unless there is danger of overrunning the PC
    > buffer.
    >
    > If necessary, pace the transmission on the PC end to give time for
    > the Stamp to react. Some PCs have a transmit buffer that might not
    > react to the flow control signal from the Stamp on a byte to byte
    > basis.
    >
    > If you use an inverting buffer like the MAX232 on the CTS/RST
    lines,
    > then the baudmode parameters become $54 for non-inverted, instead
    of
    > $4054 as written above. You could use the DTR/DSR pair, instead of
    > RTS/CTS, if that is more convenient.
    >
    > -- Tracy
    >
    >
    >
    >
    > >I am writing the PC comm software (Java), so I can set whatever
    > >options I need to. I see that I can connect DSR to DTR and RTS to
    CTS.
    > >This makes the PC see hardware flow control? Or is this faked
    (e.g. no
    > >real flow control)?
    > >
    > >I imagine the PC has buffer space so sending to it is not too bad.
    But
    > >from the PC to Stamp (BS2), how is it effectively throttled? My
    stamp
    > >will have other duties so I think flow control is essential.
    > >
    > >I am not an electronics person and fairly new to Stamps, but I've
    read
    > >a ton of stuff so far. Stamp-Stamp serial comm. seems easier with
    the
    > >explicit flow control pin.
  • ArchiverArchiver Posts: 46,084
    edited 2004-04-26 22:53
    Thanks for all the good answers. I have gotten a MAX232 chip and will
    install it. I can afford 4 general purpose stamp i/o lines for this.

    The nice thing is that this connection is then totally separate from
    the connection used for downloading code for the stamp. So switching
    from development mode to run time mode means just swapping one cable.

    All confusion is cleared up (for now anyway).

    Thanks.

    Harry

    --- In basicstamps@yahoogroups.com, "Allan Lane" <allan.lane@h...> wrote:
    > I don't think the BS2 can drive the CTS signal
    > back to the PC -- you MUST have a MAX232 or
    > equivalent for that line. The other lines look
    > correct, though.
    >
    > --- In basicstamps@yahoogroups.com, Tracy Allen <tracy@e...> wrote:
    > > Supposing you have the following connections:
    > > *PC* *Stamp*
    > > RTS from PC --> 27kohm resistor to p1 on Stamp
    > > CTS on PC <-- 220 ohm p0 on Stamp
    > > TX from PC --> Sin on Stamp (p16)
    > > RX on PC <-- Sout on Stamp (p16)
    > > COM --- COM
    > >
    > > On the Stamp, use a command like this...
    > > SERIN 16\0,$4054,6000,bailout,[noparse][[/noparse]zork]
    > > The Stamp will hold p0 at a low level until it is ready to receive,
    > > and the PC must look at its CTS line (Clear to Send), and wait up
    > > until that line goes high before sending a byte to the Stamp.
    > >
    > > The Stamp output looks like this:
    > > serout 16\1,$4054,60000,bailout,[noparse][[/noparse]"A"]
    > > The Stamp will only transmit when its p1 input (from the PC RTS
    > line)
    > > is high. So the PC should keep that line high unless it wants the
    > > Stamp to hold off on sending it data. As you noted, that will not
    > > usually be a problem unless there is danger of overrunning the PC
    > > buffer.
    > >
    > > If necessary, pace the transmission on the PC end to give time for
    > > the Stamp to react. Some PCs have a transmit buffer that might not
    > > react to the flow control signal from the Stamp on a byte to byte
    > > basis.
    > >
    > > If you use an inverting buffer like the MAX232 on the CTS/RST
    > lines,
    > > then the baudmode parameters become $54 for non-inverted, instead
    > of
    > > $4054 as written above. You could use the DTR/DSR pair, instead of
    > > RTS/CTS, if that is more convenient.
    > >
    > > -- Tracy
    > >
    > >
    > >
    > >
    > > >I am writing the PC comm software (Java), so I can set whatever
    > > >options I need to. I see that I can connect DSR to DTR and RTS to
    > CTS.
    > > >This makes the PC see hardware flow control? Or is this faked
    > (e.g. no
    > > >real flow control)?
    > > >
    > > >I imagine the PC has buffer space so sending to it is not too bad.
    > But
    > > >from the PC to Stamp (BS2), how is it effectively throttled? My
    > stamp
    > > >will have other duties so I think flow control is essential.
    > > >
    > > >I am not an electronics person and fairly new to Stamps, but I've
    > read
    > > >a ton of stuff so far. Stamp-Stamp serial comm. seems easier with
    > the
    > > >explicit flow control pin.
Sign In or Register to comment.