Both, Parallel and Serial modes of communication have certain advantages and disadvantages over one another. The serial communication is a preferred option due to its ability of long distance communication with error detection capability. The microcontrollers consist of an inbuilt hardware unit known as USART (Universal Synchronous Asynchronous Reception and Transmission) to facilitate serial transfer of data. For more details, refer to USART in AVR section.
Before starting USART, some general terms related to communication need to be understood. These terms are explained below.
Asynchronous Communication:
In this type of communication, both Transmitter (Tx) and Receiver (Rx) work on different clocks which means that they are not synchronized. Start and Stop bits are also sent with each Data byte to identify the data.
Synchronous Communication:
In this type of communication, both Tx and Rx are synchronized with the same clock and no Start or Stop bits are used.
Full-duplex Communication:
When either of the devices can send and receive data at the same instant, they are said to have full-duplex communication.
Β
Half-duplex Communication:
In this type of communication, a device can either behave as Transmitter or Receiver at an instant which means that a device canβt transmit data when it is receiving and vice versa.
Β
PICβs EUSART
PIC18F4550 has an inbuilt EUSART (Enhanced USART). Normally USART can be configured as asynchronous full-duplex communication or synchronous half-duplex communication. EUSART provides additional capabilities as compared to USART, like Automatic Baud-rate Detection. Automatic baud-rate detection means that during reception there is no need to set the baud rate at controllerβs side, EUSART sets it on its own which is certainly an advantage over USART. Baud rate and its calculation have been explained later in this article.
Registers of EUSART:
To use the EUSART of PIC18f4550 microcontroller following registers need to be configured.
1. TXSTA (Transmit Status and Control Register)
Bit 7
|
Bit 6
|
Bit 5
|
Bit 4
|
Bit 3
|
Bit 2
|
Bit 1
|
Bit 0
|
CSRC
|
TX9
|
TXEN
|
SYNC
|
SENDB
|
BRGH
|
TRMT
|
TX9D
|
TRMT: This is a read only bit which shows the status of Shift register where data is stored.
Β Β Β Β Β Β Β Β Β Β Β 1 = Transmit Shift Register Empty
Β Β Β Β Β Β Β Β Β Β Β 0 = Transmit Shift Register Full
BRGH: This bit is configured to decide the speed of Asynchronous serial communication.
Β Β Β Β Β Β Β Β Β Β Β 1 = High speed
0 = Low speed
SYNC: The mode of communication is selected by this bit.
Β Β Β Β Β Β Β Β Β Β Β 1 = Synchronous mode
0 = Asynchronous mode
TXEN: This bit is set to high to enable the transmission.
TX9:Β Β Β This bit is set to high while sending 9-bit long data.
Β Β Β Β Β Β Β Β Β Β Β 1 = Selects 9-bit transmission
0 = Selects 8-bit transmission