![ARTERY AT32F435 Series Скачать руководство пользователя страница 225](http://html1.mh-extra.com/html/artery/at32f435-series/at32f435-series_reference-manual_2977592225.webp)
AT32F435/437
Series Reference Manual
2022.11.11
Page 225
Rev 2.03
13.2.4 SPI_SCK controller
The SPI protocol adopts synchronous transmission. In master mode with the SPI being used as SPI, it
is required to generate a communication clock for data reception and transmission on the SPI, and the
communication clock should be output to the slave via IO for data reception and transmission. In slave
mode, the communication clock is provided by peripherals, and is input to the SPI via IO. In all, the
SPI_SCK controller is used for the generation and distribution of SPI_SCK, with the configuration
procedure detailed as follows:
SPI_SCK controller configuration procedure:
Clock polarity and clock phase selection: It is selected by setting the CLKPOL and CLKPHA bit.
Clock prescaler selection: Select the desired PCLK frequency by setting the CRM bit. Select the
desired prescaler by setting the MDIV[3: 0] bit.
Master/slave selection: Select SPI as master or slave by setting the MSTEN bit.
Note that the clock output is activated after the SPI is enabled in master reception-only mode, and it
remains output until when the SPI is disabled and the reception is complete.
13.2.5 CRC
There is an independent transmission and reception CRC calculation unit in the SPI. When used as SPI
through software configuration, the SPI enables CRC calculation and CRC check automatically while
the user is reading or writing through DMA or CPU. During the transmission, if the received data is not
consistent with, detected by hardware, the data in the SPI_RCRC register, and such data is exactly the
CRC value, then the CCERR bit will be set. An interrupt is generated if ERRIE=1.
The CRC function and configuration procedure of the SPI are described as follows.
CRC configuration procedure
CRC calculation polynomial is configured by setting the SPI_CPOLY register.
CRC enable: The CRC calculation is enabled by setting the CCEN bit. This operation will reset
the SPI_RCRC and SPI_TCRC registers.
Select if or when the NTC bit is set, depending on DMA or CPU data register. See the following
descriptions.
Transmission using DMA
When DMA is used to write the data to be transmitted, if the CCEN bit is enabled, the hardware calculates
the CRC value automatically according to the value in the SPI_CPOLY register and each transmitted
data, and sends the CRC value at the end of the last data transmission. This result is regarded as the
value of the SPI_TCRC register.
Reception using DMA
When DMA is used to read the data to be received, if the CCEN bit is enabled, the hardware calculates
the CRC value automatically according to the value in the SPI_CPOLY register and each received data,
and waits until the completion of CRC data reception at the end of the last data reception before
comparing the received CRC value with the value of the SPI_RCRC register. If check error occurs, the
CCERR flag is set. An interrupt is generated if the ERRIE bit is enabled.
Transmission using CPU
Unlike DMA mode, after writing the last data to be transmitted, the CPU mode requires the NTC bit to
be set by software before the end of the last data transmission.
Reception using CPU
In two-wire unidirectional full-duplex mode, follow CPU transmission mode to operate the NTC bit, the
CRC calculation and check in CPU reception mode will be completed automatically.
In single-wire unidirectional reception-only mode and single-wire bidirectional reception-only mode, it is
required to set the NTC bit before the software receives the last data when the second-to-last data is
received.