11 SYNCHRONOUS SERIAL INTERFACE (SPI)
S1C17F13 TeChniCal Manual
Seiko epson Corporation
11-5
(Rev. 1.0)
Data Format
11.4
The data length is fixed at eight bits in the SPI. The input/output permutation is configurable to MSB first or LSB
first using the SPI
n
MOD.LSBFST bit. Figure 11.4.1 shows a data format example when the SPI
n
MOD.CPOL bit =
0 and the SPI
n
MOD.CPHA bit = 0.
Cycle No.
SPICLK
n
SDO
n
SDI
n
SDO
n
SDI
n
1
SPI
n
MOD.
LSBFST bit
0
1
2
3
4
5
6
7
8
Dw7
Dr7
Dw0
Dr0
Dw6
Dr6
Dw1
Dr1
Dw5
Dr5
Dw2
Dr2
Dw4
Dr4
Dw3
Dr3
Dw3
Dr3
Dw4
Dr4
Dw2
Dr2
Dw5
Dr5
Dw1
Dr1
Dw6
Dr6
Dw0
Dr0
Dw7
Dr7
Writing Dw[7:0] to the SPI
n
TXD register
Loading Dr[7:0] to the SPI
n
RXD register
4.1 Data Format Selection Using the SPI
Figure 11.
n
MOD.LSBFST Bit
(SPI
n
MOD.CPOL bit = 0, SPI
n
MOD.CPHA bit = 0)
Operations
11.5
Initialization
11.5.1
The SPI Ch.
n
should be initialized with the procedure shown below.
1. <Master mode only> Generate a clock by controlling the 16-bit timer and supply it to the SPI Ch.
n
.
2. Configure the following SPI
n
MOD register bits:
- SPI
n
MOD.PUEN bit
(Enable input pin pull-up/down)
- SPI
n
MOD.NOCLKDIV bit
(Select master mode operating clock)
- SPI
n
MOD.LSBFST bit
(Select MSB first/LSB first)
- SPI
n
MOD.CPHA bit
(Select clock phase)
- SPI
n
MOD.CPOL bit
(Select clock polarity)
- SPI
n
MOD.MST bit
(Select master/slave mode)
3. Assign the SPI Ch.
n
input/output function to the ports. (Refer to the “I/O Ports” chapter.)
4. Set the following SPI
n
CTL register bits:
- Set the SPI
n
CTL.SFTRST bit to 1. (Execute software reset)
- Set the SPI
n
CTL.MODEN bit to 1. (Enable SPI Ch.
n
operations)
5. Set the following bits when using the interrupt:
- Write 1 to the interrupt flags in the SPI
n
INTF register.
(Clear interrupt flags)
- Set the interrupt enable bits in the SPI
n
INTE register to 1. * (Enable interrupts)
*
The initial value of the SPI
n
INTF.TBEIF bit is 1, therefore, an interrupt will occur immediately after the
SPI
n
INTE.TBEIE bit is set to 1.
Data Transmission in Master Mode
11.5.2
A data sending procedure and operations in master mode are shown below. Figures 11.5.2.1 and 11.5.2.2 show a
timing chart and a flowchart, respectively.
Data sending procedure
1. Assert the slave select signal by controlling the general-purpose output port (if necessary).
2. Check to see if the SPI
n
INTF.TBEIF bit is set to 1 (transmit buffer empty).
3. Write transmit data to the SPI
n
TXD register.
4. Wait for an SPI interrupt when using the interrupt.