The following describes the necessary steps to enable and initialize the SPI.
TI recommends using the SPI driver in the SimpleLink™ Low Power F3 Software Development Kit (SDK) when using the SPI.
1. Ensure the SVT power domain is powered up properly.
2. Enable the SPI module clock in CLKCTL by setting the CLKCTL.CLKCFG0[10] SPI0 bit.
3. Configure the IOC module to route the PICO, POCI, CS, and SCLK functionality from I/Os to the SPI module. IOCFGn.PORTCFG must be written to the correct IDs.
For each of the frame formats, the SPI is configured using the following steps:
- Make sure that the SPI.CTL1[0] ENABLE bit is cleared before making any configuration changes
- Configure the clock pre-scaler divisor by writing to the SPI.CLKCFG0[2:0] PRESC and SPI.CLKCFG1[9:0] SCR bit fields
- Write the SPI.CTL0 register with the following configuration:
- Desired clock phase and polarity, if using Motorola™ SPI mode (SPH and SPO)
- The protocol mode: Motorola SPI (4-wire or 3-wire), TI SSF, MICROWIRE (FRF)
- The data size (DSS)
- Select whether the SPI is a controller or peripheral:
- For controller operations, SPI.CTL1[2] MS is 1.
- For peripheral mode (output enabled), SPI.CTL1[2] MS bit is 0.
- For peripheral mode (output disabled), clear the SPI.CTL1[2] MS bit to 0 and set the SPI.CTL1[3] POD bit to 1.
- Optionally, configure the μDMA channel (see Chapter 19
,
and enable the µDMA options in the SPI.DMACR register. - Enable the SPI by setting the EN bit in the SPI.CTL1 register.
As an example, assume that the SPI configuration is required to operate with the following parameters:
- Controller operation
- Texas Instruments Synchronous SPI mode
- 1-Mbps bit rate
- 8 data bits
Assuming the system clock is 48MHz, the bit-rate calculation is shown in Equation 11
Equation 11. SCLK = CLKSVT / [PRESC × (1 + SCR)]
Example: 1000000 bps = 48000000Hz / [2 × (1 + 23)]
In this case, if PRESC = 0x2, SCR must be 0x17.
The configuration sequence is:
- Verify that the EN bit in the SPI.CTL1 register is cleared.
- Write the SPI.CLKCFG0 register with a value of 0x00000002.
- Write the SPI.CLKCFG1 register with a value of 0x00000017.
- Write the SPI.CTL0 register with a value of 0x00000047.
- Write the SPI.CTL1 register with a value of 0x00000004.
- The SPI is then enabled by setting the EN bit in the SPI.CTL1 register.