Understanding Serial Ports and COM Interfaces
Understanding Serial Ports and COM Interfaces
The comparison between series and parallel transmission can be explained using an analogy.
with the roads: a traditional one-lane road (on a two-way road) for
each sense corresponds to the serial transmission, and a highway with several lanes for
sense corresponds to parallel transmission, with vehicles being the bits that circulate through the
cable.
1
Originally, serial ports could only send data, not receive, so they were developed.
bidirectional ports (which are the ones found in current equipment). Therefore, the
Bidirectional serial ports require two wires for communication to take place. The
serial communication is carried out asynchronously, meaning that a signal is not necessary (or
Synchronization clock: data can be sent at random intervals. In turn, the peripheral
It must be able to distinguish the characters (a character has a length of 8 bits) among the bit sequence.
that is being sent. This is the reason why in this type of transmission, each character is
finds preceded by a START bit and followed by a STOP bit. These bits of
controls necessary for serial transmission waste 20% of the bandwidth (every 10 bits
sent, 8 are used to encrypt the character and 2 for reception). The serial ports, for
generally, they are integrated into the motherboard, which is why the connectors found at the back
from the case and are connected to the motherboard via a cable, they can be used
to connect an external element. Generally, serial connectors have 9 or 25 pins and
they have the following shape (DB9 and DB25 connectors respectively):
A PC usually has between one and four serial ports. Asynchronous serial port Through
this type of port communication is established using an asynchronous transmission protocol.
In this case, an initial signal is first sent before the first bit of each byte, character or
encoded word. Once the corresponding code is sent, a signal is immediately sent.
stop after each encoded word. The start signal is used to prepare for the
reception mechanism or receiver, the arrival and registration of a symbol, while the signal of
Stop serves to predispose the reception mechanism to take a break and prepare.
for the reception of the new symbol. The typical start-stop transmission is the one used in the
transmission of ASCII codes through the RS-232 port, such as the one established in the
operations with teletypewriters.
The RS-232 serial port (also known as COM) is of the asynchronous type, using single wiring.
from 3 threads to 25 and connects computers or microcontrollers to all types of peripherals,
from terminals to printers and modems passing through mice. The interface between the RS-232 and the
The microprocessor is generally implemented using the UART 8250 chip (8 and 16 bit computers,
PC XT) or the 16550 (IBM Personal Computer/AT and later). The original RS-232 had a connector
2
DB-25 type, however most of those pins were not used, so IBM standardized with
its IBM Personal System/2 range the use of the DB-9 connector (already introduced in the AT) that was used,
mainly on computers. However, except for the mouse, the rest of the peripherals
the DB-25 was usually presented The RS-422 standard, similar to RS-232, is a standard used in the field
modern serial ports One of the drawbacks of the early serial ports was their slowness
compared to parallel ports - we're talking about 19.2 kbits per second - however, with
As time goes by, a multitude of high-speed serial ports are appearing that make them very
interesting as they present the advantages of less wiring and solve the problem of the
decrease in speed using greater shielding, and cheaper, using the pair technique
braided. Therefore, the RS-232 port, and even many parallel ports, are being replaced.
being replaced by new serial ports such as USB, FireWire, or Serial ATA. Types of
simplex serial communication In this case, the sender and the receiver are perfectly defined and
communication is unidirectional. This type of communication is usually used in networks
of broadcasting, where receivers do not need to send any type of data to the transmitter. Duplex,
half duplex or semi-duplex In this case, both ends of the communication system fulfill
transmitter and receiver functions, and the data moves in both directions but not in a uniform manner
simultaneous. This type of communication is commonly used in the interaction between terminals and
a central computer. Full Duplex The system is similar to duplex, but the data moves
in both directions simultaneously. For it to be possible, both emitters have different
transmission frequencies or two separate communication paths, while the
semi-duplex communication usually requires only one. For data exchange between
computers this type of communications are more efficient than semi-transmissions
[Link].
Technical characteristics
Characteristics of the serial COM port
In the field of commercial electronics, it is referred to as a DB9 connector ('D-
subminiature type B, 9 pin"), this is D-subminiature type B, with 9 pins.
It was mainly used for connecting the mouse, some old types of
scanners and currently for devices such as PDAs ("Personal Digital Assistant") or
digital personal assistants.
Each port allows connecting only 1 device.
To connect and disconnect the devices, as well as for the computer to
to recognize it correctly, it is necessary to turn off and restart the computer.
3
Electrical terminals of the serial port.
The serial port has 9 pin-type contacts; the electrical lines and their description are shown.
basic.
4
Transmission speed of the COM serial port
The way to measure the transmission speed of the serial port is in Kilobytes/second (KB/s):
Applications
Advanced Serial Port Terminal is specifically designed to establish a connection with a
serial port and send/receive data on that port. Our serial port terminal application is
an essential utility as it can send and receive various data (ASCII strings, binary, octal
in hexadecimal), redirect the input/output data flow to a specific file, verify and
solve modem configuration problems without overloading the serial port.
5
To configure or initialize the serial port, it will be enough to use service 00 of the interrupt.
placing the equivalent values of the parameters in register AL, as can be seen in
figure 2. With this method, it is possible to obtain transmission frequencies ranging from 110
up to 9600 baud.
6
To send a data through the serial port, it will be enough to place the value 01 in the AH register.
corresponding to this service and in the AL record the data to be sent, invoking again the
interruption 14H. The reading of a data that has arrived at the port is achieved with service 02, which
returns the data in register AL. The reading of the port state is obtained through the service
03 of this same interruption, and it returns in the AX register the state of the port, which will contain the
bits shown in figure 3.
For example, we can use assembly language to set the serial port to 1200.
baud rate, without parity bit, without stop bit, and 8 bits, executing the following program:
This program (where all amounts are expressed in hexadecimal) can become
executable using some of the assemblers for PC, or using the DEBUG command of
DOS.
Another way to select the parameters of communication and achieve it is through the
modification and consultation of the records corresponding to the integrated circuit that manages the
7
serial communication: the UART 8250 or similar. As is known, this integrated circuit can be
managed like a port, in which it is possible to write or read its states.
Another requirement is that the number of the port over which the data transfer will take place
it must be marked by the DX register, except in cases where the port number
is less than 255 (FFh), in which case the instruction that reads or writes can point directly to
port.
Example 1.
Connection between two computers using a serial cable, one computer is left listening.
through the hyperterminal (leaving the default configuration) and the other computer is
where the program runs.
data segment
data ends
code segment
assume cs:code,ds:data,ss:pila
start:
mov AH,00; INITIALIZE PORT
mov AL, 11100111b ;default port parameters
mov DX,00 ;com1 port
INT 14h
8
MOV AL, 52; character to be sent
INT 14h
The 4CH function of the 21HF inte returns control to the operating system
MOV AH, 4CH
INT 21H
code ends
end start
Example 2.
The following is a code used to establish serial communication between a computer and
a microcontroller from the brand Motorola with the reference HC908GP32.
The code consists of sending characters from the keyboard of a computer connected via the port.
serial to the microcontroller, which in turn has a 7-segment display connected through its PTB port
segments in the following way:
7-segment display —————— Microcontroller —————— PC
The microcontroller receives characters from the PC if they are numbers from 0 to 9 then
shows on the display the letter E indicating error.
The following is the code that should be burned into the microcontroller explained step by step.
9
MAIN: BSET 0, CONFIG1; disables the COP
The entire system is configured to establish communication.
MOVE #$03, SCBR
BSET 6, SCC1
BSET 2, SCC2
BSET 3, SCC2
MOV #$FF, DDRB; configure the entire Port B as output
START: MOV $00, PTB; turn off the entire port
LDHX #MSG; load the message 'ENTER A NUMBER'
TX: LDA, X
Compare #$FF
BEQ PRINT
BRCLR TC, SCISR,*; Wait for a data to be sent to the micro
STA SCDR
AIX #$01
BRA TX
BSR DELAY
BRCLR SCRF, SCISR,*
LDA SCDR
CMP #$39
BGT ERROR
CMP #$30
BLO ERROR
SUB #$30
THIS DATE
LDHX #TABLE; load the corresponding number into the table
TXA
ADD DATA
TAX
LDA, X
EOR #$80
STA PTB; send the corresponding number to the display
BSR DELAY
BRA START
ERROR:
MOV #$F9, PTB; sends the letter E to the display
10
GO TO START; return to the beginning of the program
LOOP: NO
NOP
NOP
NOP
NOP
DEC VAR
BNE LAZO
DEC CONT
BNE CONTINUES
RTS
; envía un mensaje al computador “INGRESE UN NUMERO”
MSG: DB"ENTER A NUMBER",$FF
TABLE: DB 3F; table of numbers from 0 to 9
DB 06
DB 5B
DB 4F
DB 66
DB 6D
DB 7D
DB 07
DB 7F
DB 67
ORG RST
DW MAIN; return to the beginning of the program
11
Bibliography
[Link]
[Link]
the-hc908gp32-microcontroller/
[Link]
[Link]
[Link]
12