UG-1262
Rev. B | Page 246 of 312
SPI_DIV = SPI_SERIAL_FREQ; //configures serial clock frequency.
SPI_CTL = 0x1043; //enables SPI in master mode and transmit mode, receive FIFO
//flush enabled.
SPI_CNT.VALUE = NUM_BYTES_TO transfer; //sets the number of bytes to transfer. SPI_DMA = 0x1;
//(optional) enables FIFO to accept 16-bit
//core data writes.
SPI_TX = 0xXXXX; //(optional) up to four 16-bit core writes can be performed
//to preload FIFO.
SPI_DMA = 0x3; //enable DMA mode, enable transmit DMA request.
DMA Master Receive Configuration
The SPIx_CNT register is available in DMA receive master mode only. This register sets the number of receive bytes required by the SPI
master or the number of clocks that the master must generate. When the required number of bytes are received, no more transfers are
initiated. To initiate a DMA master receive transfer, complete a dummy read by user code. Add this dummy read to the SPIx_CNT number.
The counter counting the bytes as they are received is reset either when SPI is disabled in SPIx_CTL, Bit 0 or when the SPIx_CNT
register is modified by user code.
Performing SPI DMA Master Receive
The DMA SPI receive channel must be configured. The NVIC must be configured to enable DMA receive master interrupts. The SPI
block must be configured as follows:
SPI_DIV = SPI_SERIAL_FREQ; //configures serial clock frequency.
SPI_CTL = 0x2003;
//enable SPI in master mode and
//receive mode, 1 byte transfer.
SPI_DMA = 0x5;
//enable DMA mode, enable receive DMA request. SPI_CNT.VALUE = XXX;
//number of bytes to be received.
A = SPI_RX;
//dummy read.
The DMA transfer stops when the appropriate number of clock cycles have been generated. All DMA data transfers are 16-bit transfers.
Program the DMA accordingly. For example, if 16 bytes of data are to be received over the SPI, program the DMA to perform eight 16-bit
transfers. If 17 bytes are to be received, nine 16-bit transfers are required. The additional bytes are padded for the final DMA transfer.
Data errors occur if the DMA transfers are programmed as byte wide transfers.
The DMA transfer stops when the appropriate number of bytes have been transferred. The DMA buffer must be of the same size as
SPIx_CNT to generate a DMA interrupt when the transfer is complete. SPIx_CNT must always be ≥2.
SPI AND POWER-DOWN MODES
In master mode, before entering power-down mode, disable the SPI block in SPIx_CTL, Bit 0. In slave mode, in either mode of operation
(interrupt driven or DMA), the chip select line level must be checked via the GPIO registers using SPIx_STAT, Bit 11 to ensure that the
SPI is not communicating and that the SPI block is disabled while the chip select line is high. At power-up, the SPI block can be
reenabled. While being powered down, the following fields are retained:
All bit fields of SPIx_CTL register, except SPIx_CTL, Bit 0 is reset to 0 on power-up, which allows a clean start of the design at wakeup.
SPIx_IEN, Bits[2:0] bit field.
SPIx_DIV, Bits[5:0] bit field.
SPIx_RD_CTL, Bit 8.
SPIx_FLOW_CTL, Bit 4.
All other bit fields are not retained. As such, they are all reset on power-up. On exiting the power-down mode, the software reprograms
all nonretained registers as required. Then, the SPI block must be reenabled by setting the SPIx_CTL, Bit 0.