www
.mcu.com.cn
177
/
239
Rev.
1.00
CMS80F731x Reference Manual
20.8 SPI Data Transfer
20.8.1
SPI Transfer Starts
All SPI transfers are initiated and controlled by the master SPI device. As a slave device, the SPI will consider the
transmission starting at the first SCLK edge or the falling edge of the NSS, depending on the CPHA format chosen. When CPHA
= 0, the falling edge of the NSS indicates the start of the transmission. When CPHA = 1, the first edge on the SCLK indicates
the start of the transfer. Regardless of the CPHA mode, the transmission can be aborted by making the NSS line high, but
resetting the SPI slave logic and counter. The SELECTED SCLK rate has no effect on slave operation because the master's
clock is controlling the transmission.
When SPI is configured as a host, the transfer is initiated by software that writes to the SPDR.
20.8.2
SPI Transfer Ends
When the SPIF flag is set to 1, the SPI transfer is technically completed, but depending on the configuration of the SPI
system, there may be other tasks. Since the SPI bit rate does not affect the timing of the end period, only the fastest rate is
considered in the discussion during the end period. When the SPI is configured as a host, the SPIF asserts at the end of the
eighth SCLK cycle cycle. When the CPHA is equal to 1, the SCLK is inactive in the last half of the eighth SCLK cycle.
Because the SCLK line can be asynchronous with the slave's MCU clock, and the slave cannot access as much information
as the master does to the SCLK cycle, the end cycle is different when the SPI is running as a slave. For example, when CPHA
= 1, where the last SCLK edge occurs in the middle of the eighth SCLK cycle, the slave has no way of knowing when the
previous SCLK cycle ended. For these reasons, the slave believes that after the last bit of the serial data is sampled, the
transmission is complete, which corresponding the middle of the eighth SCLK cycle.
The SPIF flag is set at the end of the transmission, but the NSS line is still low, and the slave does not allow new data to be
written to the SPDR.