STC8A8K64D4 Series Manual
14.4 UART2
14.4.1 UART2 control register
S2SM0: Serial port 2 mode select bit.
8-bit UART, whose baud-rate is variable
9-bit UART, whose baud-rate is variable
S2SM2: UART2 multi-machine communication control enable bit. In mode 1, if the S2SM2 bit is 1 and the S2REN bit
is 1, the receiver is in the address frame filter state. In this case, the received 9
th
bit (S2RB8) can be used to filter
the address frame. If S2RB8 = 1, the frame is the address frame, address information can enter S2BUF, S2RI
becomes 1, and then address can be compared in the interrupt service routine. If S2RB8 = 0, it indicates that the
frame is not an address frame and should be discarded and keep S2RI = 0. In mode 1, if the S2SM2 bit is 0 and
the S2REN bit is 1, the receiver is in the address frame filter disabled state. Regardless of the received S2RB8
is 0 or 1, the information received can enter into the S2BUF, and make S2RI = 1. Here, S2RB8 is usually used
as check bit. Mode 0 is non-multi-machine communication mode, where S2SM2 should be 0.
S2REN: Receive enable control bit.
0: disable UART2 receive data.
1: enable UART2 receive data.
S2TB8: S2TB8 is the 9
th
bit of datum to be sent when UART2 is in mode 1, which is usually used as a parity check bit
or an address frame / data frame flag. It can be set or cleared by software as required. In mode 0, this bit is not
used.
S2RB8: S2RB8 is the 9
th
bit of datum recieved when UART2 is in mode 1, which is usually used as a parity check bit
or an address frame / data frame flag. It can be set or cleared by software as required. In mode 0, this bit is not
used.
S2TI: Transmit interrupt request flag of UART2. S2TI is set by the hardware automatically at the beginning of the stop
bit transmittion and requests interrupts to the CPU. S2TI must be cleared by software after the interrupt is
responded.
S2RI: Receive interrupt request flag of UART2. S2RI is set by hardware automatically at the middle of stop bit received,
and requests the interrupt to the CPU. After the interrupt is responded, S2RI must be cleared by software.
14.4.2 UART2 data register
S2BUF: It is used as the buffer in transmission and receiving for UART2. S2BUF is actually two buffers, reading buffer
and writing buffer. Two operations correspond to two different registers, one is write-only register (writing
buffer), the other is read-only register (reading buffer). The CPU reads serial receiving buffer when reads S2BUF,
and writes to the S2BUF will trigger the serial port to start sending data.
14.4.3 UART2 Mode 0
UART2 mode 0 is 8-bit UART mode with ariable baud rate. In this mode, a frame of data consists 10 bits: 1 start
bit, 8 data bits (LSB first) and 1 stop bit. The baud rate is variable, which can be set by the software as needed. TxD2
is the data transmitting pin, and RxD2 is the data receiving pin, the serial port is a full duplex receiver/transmitter.