UART via RS-232
communica
tion
The
UART
(universal
asynchronous
receiver/transmitter) is one of the most
common ways of exchanging data between
the MCU and peripheral components. It is
a serial protocol with separate transmit and
receive lines, and can be used for full-duplex
communication. Both sides must be initialized with
the same baudrate, otherwise the data will not be
received correctly.
RS-232 serial communication
is performed through a
9-pin SUB-D connector and the microcontroller UART
module. In order to enable this communication, it
is necessary to establish a connection between
RX
and
TX
lines on SUB-D connector and the
same pins on the target microcontroller using
DIP switches. Since RS-232 communication
voltage levels are different than
microcontroller logic levels, it is
necessary to use a RS-232
Transceiver circuit, such as
MAX3232
as shown
on
Figure 6-1
.
D
AT
A BUS
CN37
1
6
5
9
1
6
5
9
Bottom view
SUB-D 9p
R32
100K
VCC-MCU
VCC-MCU
U4
MAX3232
C1+
V+
C1 -
C2+
C2 -
V-
T2 OUT
R2 IN
VCC
GND
T1 OUT
R1 IN
R1 OUT
T1 IN
T2 IN
R2 OUT
1
2
3
4
5
6
7
8
1
6
2
7
3
8
4
9
5
16
15
14
13
12
11
10
9
C28
100nF
C30
100nF
TX-232
RX-232
RS-232
C29
100nF
C31
100nF
E8
10uF
VCC-MCU
RX
TX-FTDI
J3
ON
TX
J4
ON
TX-232
RA2
RB7
RC4
RD6
RC6
RB5
RB2
RB1
RA3
RB5
RC5
RD7
RC7
RB2
RB1
RB4
SW2
DIP SW 8
SW1
DIP SW 8
M1X3
M1X3
RX-FTDI
RX-232
16
15
14
13
12
11
10
9
16
15
14
13
12
11
10
9
1
2
3
4
5
6
7
8
1
2
3
4
5
6
7
8
Figure 6-1: RS-232 connection schematics
Enabling RS-232
In order to enable RS-232
communication, you must set
J3
and
J4
jumpers in the
RS-232
position, and enable desired
RX
and
TX
lines via
SW1
and
SW2
DIP switches. For example, if you
want to enable RS-232 connection
on UART1 module of the default
PIC18F45K22
chip, you should
enable
SW1.1
(RC7) and
SW2.1
(RC6) lines.
page 16