![](http://datasheet.mmic.net.cn/260000/PIC18F458ELQTP_datasheet_15942934/PIC18F458ELQTP_193.png)
2002 Microchip Technology Inc.
Preliminary
DS41159B-page 191
PIC18FXX8
18.3
USART Synchronous Master
Mode
In Synchronous Master mode, the data is transmitted in
a half-duplex manner (i.e., transmission and reception
do not occur at the same time). When transmitting data,
the reception is inhibited and vice versa. Synchronous
mode is entered by setting bit SYNC (TXSTA register).
In addition, enable bit SPEN (RCSTA register) is set, in
order to configure the RC6/TX/CK and RC7/RX/DT I/O
pins to CK (clock) and DT (data) lines, respectively. The
Master mode indicates that the processor transmits the
master clock on the CK line. The Master mode is
entered by setting bit CSRC (TXSTA register).
18.3.1
USART SYNCHRONOUS MASTER
TRANSMISSION
The USART transmitter block diagram is shown in
Figure 18-1. The heart of the transmitter is the Transmit
(serial) Shift register (TSR). The shift register obtains
its data from the Read/Write Transmit Buffer register
(TXREG). The TXREG register is loaded with data in
software. The TSR register is not loaded until the last
bit has been transmitted from the previous load. As
soon as the last bit is transmitted, the TSR is loaded
with new data from the TXREG (if available). Once the
TXREG register transfers the data to the TSR register
(occurs in one T
CY
), the TXREG is empty and interrupt
bit TXIF (PIR registers) is set. The interrupt can be
enabled/disabled by setting/clearing enable bit TXIE
(PIE registers). Flag bit TXIF will be set, regardless of
the state of enable bit TXIE and cannot be cleared in
software. It will reset only when new data is loaded into
the TXREG register. While flag bit TXIF indicates the
status of the TXREG register, another bit TRMT
(TXSTA register) shows the status of the TSR register.
TRMT is a read only bit, which is set when the TSR is
empty. No interrupt logic is tied to this bit, so the user
has to poll this bit in order to determine if the TSR reg-
ister is empty. The TSR is not mapped in data memory,
so it is not available to the user.
Steps to follow when setting up a Synchronous Master
Transmission:
1.
Initialize the SPBRG register for the appropriate
baud rate (Section 18.1).
2.
Enable the synchronous master serial port by
setting bits SYNC, SPEN, and CSRC.
3.
If interrupts are desired, set enable bit TXIE.
4.
If 9-bit transmission is desired, set bit TX9.
5.
Enable the transmission by setting bit TXEN.
6.
If 9-bit transmission is selected, the ninth bit
should be loaded in bit TX9D.
7.
Start transmission by loading data to the TXREG
register.
Note:
TXIF is not cleared immediately upon load-
ing data into the transmit buffer TXREG. The
flag bit becomes valid in the second instruc-
tion cycle following the load instruction.
TABLE 18-8:
REGISTERS ASSOCIATED WITH SYNCHRONOUS MASTER TRANSMISSION
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value on
POR, BOR
Value on
all other
RESETS
INTCON
PIR1
PIE1
IPR1
RCSTA
TXREG
TXSTA
SPBRG
Legend:
x
= unknown, - = unimplemented, read as '0'. Shaded cells are not used for Synchronous Master Transmission.
GIE/GIEH
PSPIF
PSPIE
PSPIP
SPEN
USART Transmit Register
CSRC
Baud Rate Generator Register
PEIE/GIEL
ADIF
ADIE
ADIP
RX9
TMR0IE
RCIF
RCIE
RCIP
SREN
INT0IE
TXIF
TXIE
TXIP
CREN
RBIE
SSPIF
SSPIE
SSPIP
ADDEN
TMR0IF
CCP1IF
CCP1IE
CCP1IP
FERR
INT0IF
TMR2IF
TMR2IE
TMR2IP
OERR
RBIF
TMR1IF
TMR1IE
TMR1IP
RX9D
0000 000x
0000 000u
0000 0000
0000 0000
0000 0000
0000 0000
0000 0000
0000 0000
0000 000x
0000 000x
0000 0000
0000 0000
TX9
TXEN
SYNC
—
BRGH
TRMT
TX9D
0000 -010
0000 -010
0000 0000
0000 0000