13 SYNCHRONOUS SERIAL INTERFACE (SPIA)
S1C17M20/M21/M22/M23/M24/M25
Seiko Epson Corporation
13-5
TECHNICAL MANUAL (Rev. 1.0)
13.4 Data Format
The SPIA data length can be selected from 2 bits to 16 bits by setting the SPI
n
MOD.CHLN[3:0] bits. The input/
output permutation is configurable to MSB first or LSB first using the SPI
n
MOD.LSBFST bit. Figure 13.4.1 shows
a data format example when the SPI
n
MOD.CHLN[3:0] bits = 0x7, the SPI
n
MOD.CPOL bit = 0 and the SPI
n
MOD.
CPHA bit = 0.
Cycle No.
SPICLKn
SDOn
SDIn
SDOn
SDIn
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
SPInMOD.
LSBFST bit
0
1
Writing Dw[7:0] to the SPInTXD register
Loading Dr[7:0] to the SPInRXD register
Figure 13.4.1 Data Format Selection Using the SPInMOD.LSBFST Bit
(SPInMOD.CHLN[3:0] bits = 0x7, SPInMOD.CPOL bit = 0, SPInMOD.CPHA bit = 0)
13.5 Operations
13.5.1 Initialization
SPIA 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 SPIA 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 SPIA 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 SPIA 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.
13.5.2 Data Transmission in Master Mode
A data sending procedure and operations in master mode are shown below. Figures 13.5.2.1 and 13.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.