15 SPi
15-2
Seiko epson Corporation
S1C17153 TeChniCal Manual
(Rev. 1.0)
note
: Use an I/O (P) port to output the slave select signal when the SPI module is configured to master
mode.
The SPI input/output pins (SDI
x
, SDO
x
, SPICLK
x
, #SPISS
x
) are shared with I/O ports and are initially set as gen-
eral purpose I/O port pins. The pin functions must be switched using the port function select bits to use the general
purpose I/O port pins as SPI input/output pins.
For detailed information on pin function switching, see the “I/O Ports (P)” chapter.
SPi Clock
15.3
The master mode SPI uses the 8-bit timer (T8) Ch.0 output clock or a PCLK/4 clock to generate the SPI clock. This
clock is output from the SPICLK
x
pin to the slave device while also driving the shift register.
Use MCLK/SPI_CTL
x
register to select whether the T8 Ch.0 output clock or PCLK/4 clock is used.
Setting MCLK to 1 selects the T8 Ch.0 output clock; setting to 0 selects the PCLK/4 clock.
Using the T8 Ch.0 output clock enables programmable transfer rates. For more information on T8 control, see the
“8-bit timer (T8)” chapter.
PCLK
8-bit timer Ch.0 output clock
or
PCLK/4
SPI clock (SPICLK
x
output)
3.1 Master Mode SPI Clock
Figure 15.
In slave mode, the SPI clock is input via the SPICLK
x
pin.
Data Transfer Condition Settings
15.4
The SPI module can be set to master or slave modes. The SPI clock polarity/phase and bit direction (MSB first/LSB
first) can also be set via the SPI_CTL
x
register. The data length is fixed at 8 bits.
note
: Make sure the SPI module is halted (SPEN/SPI_CTL
x
register = 0) before master/slave mode se-
lection and clock condition settings.
Master/slave mode selection
MSSL/SPI_CTL
x
register is used to set the SPI module to master mode or slave mode. Setting MSSL to 1 sets
master mode; setting it to 0 (default) sets slave mode. In master mode, data is transferred using the internal
clock. In slave mode, data is transferred by inputting the master device clock.
SPi clock polarity and phase settings
The SPI clock polarity is selected by CPOL/SPI_CTL
x
register. Setting CPOL to 1 treats the SPI clock as ac-
tive Low; setting it to 0 (default) treats it as active High.
The SPI clock phase is selected by CPHA/SPI_CTL
x
register.
As shown below, these control bits set transfer timing.