www
.mcu.com.cn
175
/
239
Rev.
1.00
CMS80F731x Reference Manual
20.7 SPI Clock Control Logic
20.7.1
SPI Clock Phase and Polarity Control
The software can choose to use either of the four combinations of two control bits (phase and polarity of the serial clock
SCLK) in the SPI control register (SPCR). Clock polarity is specified by the CPOL control bit, and the CPOL control bit selection
high or low level when the transmission is idle has no significant effect on the transmission format. The Clock Phase (CPHA)
control bit selects one of two largely different transmission formats. The clock phase and polarity of the master SPI device and
the communication slave device should be the same. In some cases, the phase and polarity are changed during transmission
to allow the host device to communicate with a peripheral slave with different requirements. The flexibility of the SPI system
allows direct connection to almost all existing synchronous serial peripherals.
20.7.2
SPI Transfer Format
During SPI transmission, data is sent simultaneously (serially shift out) and received (serially shift in). The serial clock line
is synchronized with the shift and sampling of the two serial data lines. Slave selection line allows the individual selection of
slave SPI devices; Slaves that are not selected do not interfere with SPI bus activity. On the SPI host device, the slave selection
line may be selectively used to indicate multi-master bus competition.
20.7.3
CPHA=0 Transfer Format
The following figure shows a timing diagram of an SPI transmission with a CPHA of 0. SCLK shows two waveforms: one
for CPOL equal to 0 and one for CPOL equal to 1. The figure can be described as a master device or slave device timing diagram
through SCLK, where the master in/out (MISO) and master out/out (MOSI) pins are directly connected between the master and
slave. The MISO signal is output from the Slave and the MOSI signal is the host output. The slave selection input of the NSS
line is slave; The NSS pin of the host is not displayed, but is assumed to be invalid. The NSS pin of the host must be high. This
timing diagram functionally describes how the transmission takes place; It should not be used as a substitute for datasheet
parameter information.
SCLK
(CPOL=0)
D7
D6
D5
D4
D3
D2
D1
D0
D7
D6
D5
D4
D3
D2
D1
D0
MOSI
MISO
NSS
SCLK
(CPOL=1)
When CPHA=0, the NSS line must unset and Reset between each consecutive serial byte. In addition, if the slave writes
data to the SPI Data Register (SPDR) when the NSS is low, a write collision error is generated. When CPHA = 1, the NSS line
may remain low between consecutive transmissions (which can always be kept low). In systems with a single fixed master and
a single slave driving the MISO data line, this format is sometimes preferred.