This section describes the procedure in which to
configure the SPI module for operation. To prevent unwanted and unforeseen events
from occurring during or as a result of initialization changes, clear the SPISWRESET
bit before making initialization changes, and then set this bit after initialization
is complete. While the SPI is held in reset (SPISWRESET = 0), configuration can be
changed in any order. The following list shows the SPI configuration procedure in a
logical order. However, the SPI registers can be written with single 16-bit writes,
so the order is not required with the exception of SPISWRESET.
Note: Do not change the SPI configuration
when communication is in progress.
To change the SPI configuration:
- Clear the SPI Software Reset
bit (SPISWRESET) to 0 to force the SPI to the reset state.
- Configure the SPI as desired:
- Select either master or
slave mode
(MASTER_SLAVE).
- Choose SPICLK
polarity and phase (CLKPOLARITY and CLK_PHASE).
- Set the desired baud
rate (SPIBRR).
- Enable high-speed mode, if desired (HS_MODE).
- Set the SPI character
length (SPICHAR).
- Clear the SPI Flags
(OVERRUN_FLAG, INT_FLAG).
- Enable SPISTE
inversion (STEINV), if needed.
- Enable 3-wire mode (TRIWIRE), if needed.
- If using FIFO
enhancements:
- Enable the
FIFO enhancements (SPIFFENA).
- Clear the
FIFO Flags (TXFFINTCLR, RXFFOVFCLR, and RXFFINTCLR).
- Release
transmit and receive FIFO resets (TXFIFO and
RXFIFORESET).
- Release SPI
FIFO channels from reset (SPIRST).
- If interrupts are used:
- In non-FIFO mode,
enable the receiver overrun and/or SPI interrupts (OVERRUNINTENA and
SPIINTENA).
- In FIFO mode, set the
transmit and receive interrupt levels (TXFFIL and RXFFIL) then
enable the interrupts (TXFFIENA and RXFFIENA).
- Set SPISWRESET to 1 to
release the SPI from the reset state.