🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.computer.drivers.wanted
Article #220

Re: How to use the serial port ?

#220
From: Richard Steven Walz
Date: Thu, 21 Aug 1997 00:00
341 lines
16329 bytes
In article <01bcad87$9edb65a0$LocalHost@club-internet.fr.club-internet.fr>,
Thunder <BrunoM@mail.dotcom.fr> wrote:
>I want to drive some circuits from the serial port, but i don't how to
>affect the state of the output and input bits (Tx, Rx, DTS, RTS, RI, DCT
>etc..) in order to use my COM2 serial port instead of the // port wher's
>the printer's plugged.
>
>Thanx to everyone who will tell me the input/output bits' weight on the
>bytes at &H2F9 and following.
>
>Regards, Bruno.
>________________________________________
>/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
>   Thunder (Bruno)
>temp: bmnice@club-internet.fr
>fixe: BrunoM@mail.dotcom.fr
> Microsoft Windows 95
>  crashes faster        
>than any other OS    
>/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
>��������������������������������������������������������
----------------------------------
Ah! Pretty XPC (eXtended PC ASCII) character graphics! I got some too!:

 ���������۲�����������������۲�������� 
 ���������۲�����������������۲��������

-------------------
 ���������۲��������

 Alt-176,177,178,219,178,177,176 simple.
-------------------------------------------
Anyway:
Controlling COM port bits-pins:
Subdir/File on my Web-FTP site: LPT/com-pins.io
-Steve
--
-Steve Walz  rstevew@armory.com  ftp://ftp.armory.com:/pub/user/rstevew
-Electronics Site!! 1000 Files/50 Dirs!! http://www.armory.com/~rstevew
Europe:(Italy) ftp://ftp.cised.unina.it:/pub/electronics/ftp.armory.com
Oz:.AU ftp://ftp.peninsula.apana.org.au:/pub/electronics/ftp.armory.com
----------------------------------------------------------------------------- 

LPT/com-pins.io

My file on using the 8250/16450/16550 UARTs to control and read their
handshake lines directly. Lines available are: RTS DTR outputs, and
CTS DSR DCD and RI inputs. Thus four inputs and two outputs. And without
even getting involved with the serial port job of the UART! Of course
these signals are -12/+12VDC which need converting to +5/0VDC TTL levels
for external TTL. But they are also useful in that they can be grounded
without harm at all!! They are current limited. They can also be used
to SUPPLY a small amount of current! Read ON!
-Steve Walz   rstevew@armory.com  http://www.armory.com/~rstevew/

    ( All below extracted from Christian Blum's Serial Port FAQ )

      _________________________________________________________________
   
   
                                  REGISTERS
                                       
   First some tables; full descriptions follow. Base addresses as
   specified by IBM for a full-blown system; compare the section on
   logical & physical names.
   

1st  2nd  3rd  4th  Offs. DLAB  Register
------------------------------------------------------------------------------
3F8h 2F8h 3E8h 2E8h  +0     0   RBR  Receive Buffer Register (read only) or
                                THR  Transmitter Holding Register (write only)
3F9h 2F9h 3E9h 2E9h  +1     0   IER  Interrupt Enable Register
3F8h 2F8h 3E8h 2E8h  +0     1   DL   Divisor Latch (LSB)  These registers can
3F9h 2F9h 3E9h 2E9h  +1     1   DL   Divisor Latch (MSB)  be accessed as word
3FAh 2FAh 3EAh 2EAh  +2     x   IIR  Interrupt Identification Register (r/o) or
                                FCR  FIFO Control Register (w/o, 16550+ only)
3FBh 2FBh 3EBh 2EBh  +3  *  x   LCR  Line Control Register
3FCh 2FCh 3ECh 2ECh  +4  *  x   MCR  Modem Control Register
3FDh 2FDh 3EDh 2EDh  +5  |  x   LSR  Line Status Register
3FEh 2FEh 3EEh 2EEh  +6  *  x   MSR  Modem Status Register
3FFh 2FFh 3EFh 2EFh  +7  |  x   SCR  Scratch Register (16450+ and some 8250s,
                         |           special use with some boards)
                         |
                         V
           80h      40h      20h      10h      08h      04h      02h      01h
Register  Bit 7    Bit 6    Bit 5    Bit 4    Bit 3    Bit 2    Bit 1    Bit 0
-------------------------------------------------------------------------------
IER         0        0        0        0      EDSSI    ELSI     ETBEI    ERBFI
IIR (r/o) FIFO en  FIFO en    0        0      IID2     IID1     IID0    pending
FCR (w/o)  - RX trigger -     0        0      DMA sel  XFres    RFres   enable
*********
LCR       DLAB     SBR    stick par  even sel Par en  stopbits  - word length -
*********                                                     ***************
MCR         0        0       AFE     Loop     OUT2     OUT1     RTS     DTR
*********                                                     ***************
LSR       FIFOerr  TEMT     THRE     Break    FE       PE       OE      RBF
*******************************************                   ***************
MSR       DCD      RI       DSR      CTS      DDCD     TERI     DDSR    DCTS
*******************************************                   ***************
   
     -----------------------------------------------------------
       
     *** LCR (Line Control Register) 3FBh 2FBh 3EBh 2EBh +3 r/w
       
       This register allows you to select the transmission protocol. It
       also contains the DLAB bit which switches the function of the
       addresses +0 and +1.
       

   Bit 1  Bit 0    word length         Bit 2      Stop bits
     0      0        5 bits              0            1
     0      1        6 bits              1          1.5/2
     1      0        7 bits         (1.5 if word length is 5)
     1      1        8 bits   (1.5 does not work with some chips, see above)

   Bit 5  Bit 4  Bit 3     Parity type       Bit 6   SOUT condition
     x      x      0       no parity           0     normal operation
     0      0      1       odd parity     ***  1     forces TxD +12V (break)
     0      1      1       even parity       Bit 7   DLAB
     1      0      1       mark parity         0     normal registers
     1      1      1       space parity        1     divisor at reg 0, 1
   
       Mark parity: The parity bit is always '1' (the line is 'low').
       Space parity: The parity bit is always '0' (the line is 'high').
       
            -----------------------------------------------
       
     *** MCR (Modem Control Register) 3FCh 2FCh 3ECh 2ECh +4 r/w
       
       This register allows to program some modem control lines and to
       switch to loopback mode.
       
     ***Bit 0
                Programs -DTR. If set, -DTR is low and the DTR pin of the
                port goes 'high'.
                
     ***Bit 1
                Programs -RTS. dito.
                
        Bit 2
                Programs -OUT1. Normally not used in a PC, but used with
                some multi-port serial adapters to enable or disable a
                port. Best thing is to write a '1' to this bit.
                
        Bit 3
                Programs -OUT2. If set to 1, interrupts generated by the
                UART are transferred to the ICU (Interrupt Control Unit)
                while 0 sets the interrupt output of the card to high
                impedance. (This is PC-only).
                
     ***Bit 4
                '1': local loopback. All outputs disabled. This is a
                means of testing the chip: you 'receive' all the data you
                send. Interrupts are fully operational in this mode.
                
        Bit 5
                (Texas Instruments TL16C550C only, maybe some more; this
                is not a standard feature) '1': Enable automatic flow
                control. If RTS (bit 1) is '0', only auto-CTS is done,
                which means that no more characters are sent from the
                FIFO and no more Tx interrupts are generated as long as
                CTS is '0'. If RTS (bit 1) is '1', the RTS signal is
                dropped whenever the FIFO trigger level is reached. Note
                that if this bit is '1', delta CTS (see below) won't
                generate a modem status interrupt!
                

      --------------------------------------------------------------  
                
   
     * MSR (Modem Status Register) 3FEh 2FEh 3EEh 2EEh +6 r/w
       
       This register allows you to check several modem status lines. The
       delta bits are set if the corresponding signals have changed state
       since the last reading (except for TERI which is only set if -RI
       changed from active-low to inactive-high, that is if the RI line
       at the port changed from 'high' to 'low' and the phone stopped
       ringing).
       
     ***Bit 0
                Delta CTS. Set if CTS has changed state since last
                reading.
                
     ***Bit 1
                Delta DSR. Set if DSR has changed state since last
                reading.
                
     ***Bit 2
                TERI. Set if -RI has changed from low to high (ie. RI at
                port has changed from +12V to -12V).
                
     ***Bit 3
                Delta DCD. Set if DCD has changed state since last
                reading.
                
     ***Bit 4
                CTS. 1 if 'high' at port.
                
     ***Bit 5
                DSR. dito.
                
     ***Bit 6
                RI. dito.
                
     ***Bit 7
                DCD.
                
   
    ***In loopback mode (MCR bit 4 = 1), bit 4 shows the state of RTS
       (MCR bit 1), bit 5 shows the state of DTR (MCR bit 0), RI shows
       the state of OUT1 (MCR bit 2), and DCD shows the state of OUT2
       (MCR bit 3). The delta registers act accordingly to the 'level
       transitions' of the data written to MCR. This is a good means of
       testing if a UART is present.
       
---------------------------------------------------------------------------

Some Posts About This Topic:
----------------------------

From: flanders@groupz.net (Jerry Flanders)
Subject: Re: PC Serial Port Programming
Date: Sat, 13 Jul 1996 17:47:25 GMT

>SOMEBODY writes:
>>>Does anyone know how to manipulate any of the other lines and make them
>>>outputs? The ideal is a line that can be set either to a logic 1 or 0 and
>>>stay there until a program initiates controlled change.
================================================================
I don't have the full original post, but I think the following may
apply. 

You have direct control over the serial ports. In BASIC, you use the
OUT instruction (you are putting data on the I/O bus).

Control of each serial port is effected through a set of 7 eight-bit
registers STARTING at the address "given" for that port (usually 3F8
hex for primary, 2F8 for secondary. You can look up the usual
addresses used by ports 3 and 4, calculate the offsets, and use them
similarly - the following applies to ports 1 and 2 directly).

***Two of the lines that are very easy to get at and use are the DTR (pin
20 on the 25 pin socket) and the RTS (pin 4). These are controlled
throught the "MODEM CONTROL" register, located at address  3FC  / 2FC
hex for the primary/secondary port.

BASIC code:
OUT (&H3FC),1   REM TURN ON THE DTR LINE OF PRIMARY (COM 1)
OUT (&H3FC),0   REM TURN OFF THE DTR LINE OF PRIMARY (COM 1)
OUT (&H2FC),1   REM TURN ON THE DTR LINE OF SECONDARY (COM 2)
OUT (&H2FC),0   REM TURN OFF THE DTR LINE OF SECONDARY (COM 2)

***Use bit zero for the DTR (above example), bit one for the RTS (OUT the
value 2).

I have used these techniques for control before - they DO work. If
you have problems I may have dropped a bit or two in interpreting this
data from IBM's "Technical Reference" . I turned on/off an external
120 VAC device by letting the serial port's DTR line trigger a SSR
(solid state relay) that controlled the device. Only problem is that
you give up the serial port for other uses. Works fine on a cheapie
system that is dedicated to control purposes, however. These lines are
supposed to be pretty robust - you are not likely to zap anything with
a momentary short or application of a (reasonable) overvoltage, etc.

You don't need the BASIC "OPEN" instruction unless you are setting up
the usual buffers and interrupt mechanisms required for serial
communications.

Incidentally, you have excellent control over ALL of the UART's
functions through these techniques - oddball baud rates, word lengths,
etc. You can do tricks like setting up a non-standard baud rate with
an otherwise standard operating system-supported comm channel by
setting up the channel through the OS, then changing the baud rate of
the UART separately by sending the appropriate rate-setting value to
the modem control register using the above techniques.

Best Regards

Jerry Flanders    W4UKU    South Carolina
flanders@groupz.net

------------------------------------------------------------------

From: kcsbvr@icns.nl (Bas van Rossem)
Subject: Re: PC Serial Port Programming
Date: Mon, 15 Jul 1996 10:26:13 GMT

Jim Law <jlaw@robominer.com> wrote:

>Kevin Hoskins wrote:
>> 
>> I am trying to connect a 2-channel analog-to-digital converter and a dual
>> digital-to-analog converter to a PC serial port. I can communicate with
>> each device individually but I need one more line to act as a "select" so
>> that both devices can share the clock and data lines. I have successfully
>> used two output lines, DTR and RTS, to send a conversion clock signal and
>> channel selection data to the ADC or clock and data to the DAC. A third
>> line, RI, is used to transfer data from the ADC to the PC.
>> 
>> Does anyone know how to manipulate any of the other lines and make them
>> outputs? The ideal is a line that can be set either to a logic 1 or 0 and
>> stay there until a program initiates controlled change. The second choice
>> is to be able to create a program initiated pulse that occurs only when
>> needed.
>> 
>> (I have tried TX as on output, but it I cannot make it toggle under
>> program control with predictable results.)
>> 
>> Email responses preferred to kevnjoni@garlic.com
>> 
>> Thanks,
>> 
>> Kevin


***>Try and see if the 8250 has a force line break function which will 
>take the TXD line to a space condition as long as the break is active.
>Normally, with no characters going out, the line will be mark state.

>Jim Law
>jlaw@robominer.com

***My point exactly....
***Bit 6 of the line control register (base address+3) controls this
***feature.

Bas
kcsbvr@icns.nl

Sanity is the worst form of insanity....

------------------------------------------------------------------------
END
-Steve
-- 
-Steve Walz  rstevew@armory.com  ftp://ftp.armory.com:/pub/user/rstevew
-Electronics Site!! 1000 Files/50 Dirs!! http://www.armory.com/~rstevew
Europe:(Italy) ftp://ftp.cised.unina.it:/pub/electronics/ftp.armory.com
Oz:.AU ftp://ftp.peninsula.apana.org.au:/pub/electronics/ftp.armory.com
Technical Details
Message-ID: <5thjeu$9lb@news.scruz.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <01bcad87$9edb65a0$LocalHost@club-internet.fr.club-internet.fr>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f78f1,7dd782511b6ffa25
X-Google-Attributes: gidf78f1,public
X-Google-Thread: 115b28,7dd782511b6ffa25
X-Google-Attributes: gid115b28,public
X-Google-Thread: f9e32,7dd782511b6ffa25
X-Google-Attributes: gidf9e32,public
X-Google-Thread: f645d,7dd782511b6ffa25
X-Google-Attributes: gidf645d,public
X-Google-Thread: f7646,7dd782511b6ffa25
X-Google-Attributes: gidf7646,public
X-Google-Thread: 111d0a,7dd782511b6ffa25
X-Google-Attributes: gid111d0a,public
From: rstevew@armory.com (Richard Steven Walz)
Subject: Re: How to use the serial port ?
Date: 1997/08/21
Message-ID: <5thjeu$9lb@news.scruz.net>
X-Deja-AN: 265747390
References: <01bcad87$9edb65a0$LocalHost@club-internet.fr.club-internet.fr>
Organization: The Armory
Newsgroups: alt.computer.drivers.wanted,comp.lang.basic.visual,comp.msdos.programmer,fr.comp.lang.basic,microsoft.public.basic.dos,sci.electronics.basics