Serial Port Complete - Latest Microcontroller projects

(lily) #1
Ports for Embedded Systems

Bit 7 isn’t used in asynchronous communications and should maintain the
default value.


Bit 6 (TX9) sets the number of bits to transmit to 8 (0) or 9 (1).


Bit 5 (TXEN) enables transmitting.


Bit 4 (SYNC) is set to zero for asynchronous communications.


Bit 3 (SENDB) is set to zero for normal communications and is set to 1 to
enable sending a Sync Break character, which is a special character defined by
the LIN bus protocol used in automotive applications. The character consists of
a Start bit, 12 zeros, and a Stop bit. When SENDB = 1, TXEN = 1, and a value
is loaded from TXREG into the TSR, the EUSART ignores the data in the
TSR and instead sends a Sync Break character.


Bit 2 (BRGH) selects whether to use the high speed (1) or low speed (0) value
for the bit rate specified in the SPBRG and SPBRGH registers as described later
in this chapter.


Bit 1 (TRMT) indicates whether the TSR is empty (1) or full (0). This bit
doesn’t control an interrupt but firmware can read the bit.


Bit 0 (TX9D) holds the ninth bit of data to send when TX9 = 1. Firmware
must provide the value. If used, firmware should write a value to TX9D before
writing a byte to send to TXREG.


5    

 5
5 #


The receive status and control register (RCSTA) enables monitoring and con-
trolling received data. The register also contains the SPEN bit, which enables
the serial port by configuring the dedicated port pins for serial data. The RX9D
bit holds an optional received ninth data or parity bit. To enable receiving 8-bit
asynchronous data, set the register to 90h.


To ensure reading valid values, firmware should read any bits of interest in
RCSTA before reading RCREG to obtain a received byte. Reading RCREG
causes bits RX9D, OERR, and FERR to update for the next received byte.


Bit 7 (SPEN), enables the serial port by configuring the RX and TX pins as the
input and output for USART data.


Bit 6 (RX9) enables receiving 9-bit data.


Bit 5 (SREN) has no function in asynchronous communications and should
maintain the default value.


Bit 4 (CREN) enables the receiver.

Free download pdf