User'S Guide: Tms320Dm644X Dmsoc Serial Peripheral Interface (Spi)
User'S Guide: Tms320Dm644X Dmsoc Serial Peripheral Interface (Spi)
User's Guide
Preface ............................................................................................................................... 6
1 Introduction................................................................................................................ 8
1.1 Purpose of the Peripheral ....................................................................................... 8
1.2 Features ........................................................................................................... 8
1.3 Functional Block Diagram ....................................................................................... 9
1.4 Industry Standard(s) Compliance Statement ................................................................. 9
2 Peripheral Architecture ................................................................................................ 9
2.1 ..................................................................................................... 9
Clock Control
2.2 Signal Descriptions ............................................................................................. 10
2.3 Pin Multiplexing ................................................................................................. 10
2.4 SPI Operation ................................................................................................... 10
2.5 Reset Considerations .......................................................................................... 17
2.6 Initialization ...................................................................................................... 17
2.7 Interrupt Support ................................................................................................ 18
2.8 EDMA Event Support .......................................................................................... 19
2.9 Power Management ............................................................................................ 20
2.10 SPI Internal Loop-Back Test Mode ........................................................................... 20
2.11 Emulation Considerations ..................................................................................... 20
3 Registers .................................................................................................................. 21
3.1 SPI Global Control Register 0 (SPIGCR0) .................................................................. 21
3.2 SPI Global Control Register 1 (SPIGCR1) .................................................................. 22
3.3 SPI Interrupt Register (SPIINT) ............................................................................... 23
3.4 SPI Interrupt Level Register (SPILVL) ....................................................................... 24
3.5 SPI Flag Register (SPIFLG) ................................................................................... 25
3.6 SPI Pin Control Register (SPIPC0) .......................................................................... 26
3.7 SPI Pin Control Register 2 (SPIPC2) ........................................................................ 27
3.8 SPI Shift Register (SPIDAT1) ................................................................................. 28
3.9 SPI Buffer Register (SPIBUF)................................................................................. 29
3.10 SPI Emulation Register (SPIEMU) ........................................................................... 30
3.11 SPI Delay Register (SPIDELAY) ............................................................................. 31
3.12 SPI Default Chip Select Register (SPIDEF)................................................................. 32
3.13 SPI Data Format Registers (SPIFMTn) ...................................................................... 33
3.14 SPI Interrupt Vector Register 0 (INTVECT0) ............................................................... 34
3.15 SPI Interrupt Vector Register 1 (INTVECT1) ............................................................... 35
Appendix A Revision History ............................................................................................. 36
1 Introduction
This document describes the serial peripheral interface (SPI) in the TMS320DM644x Digital Media
System-on-Chip (DMSoC).
1.2 Features
The SPI has the following features:
• 16-bit shift register
• Receive buffer register
• 8-bit clock prescaler
• Programmable SPI clock frequency range
• Programmable character length (2 to 16 bits)
• Programmable clock phase (delay or no delay)
• Programmable clock polarity (high or low)
• Two chip select signals (SPI_EN0 and SPI_EN1) provide the ability to control two slave devices
Peripheral Architecture
1.3 Functional Block Diagram
A block diagram of the major components of the SPI is shown in Figure 1.
SPI_DO
Interrupt to
ARM Interrupt Controller
Clock Prescaler
SYSCLK5 (PRESCALEn)
2 Peripheral Architecture
This section describes the architecture of the SPI.
Peripheral Architecture
Peripheral Architecture
2.4.1.1 Character Length
The character length is configured by the CHARLENn bit. Legal values are 2 bits (2h) to 16 bits (10h). The
character length is independently configured for each of the four data formats.
Transmit data is written to SPIDAT1. The transmit data must be written right-justified in the SPIDAT1 field.
The SPI automatically sends out the data correctly based on the chosen data format. Figure 2 shows an
example of how transmit data should be written for a 14-bit character length.
Figure 2. Right-Aligned Transmit Data in SPIDAT1 Field of the SPI Shift Register (SPIDAT1)
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
X X 1 0 1 0 1 0 1 0 1 0 1 0 1 0
When a full word of receive data arrives in SPIDAT1, it is copied to the SPI buffer register (SPIBUF). The
received data is read from SPIBUF by the CPU or the EDMA. The received data in SPIBUF is
right-justified. If the character length is less than 16 bits, additional bits may be present in SPIBUF left
over from the transmitted data. But since the data in SPIBUF is right-justified and the character length is
known, the additional bits can be ignored. Figure 3 shows an example of how receive data will be aligned
for a 14-bit character length.
Figure 3. Right-Aligned Receive Data in SPIBUF Field of the SPI Buffer Register (SPIBUF)
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
X X 1 0 1 0 1 0 1 0 1 0 1 0 1 0
Peripheral Architecture
Figure 4 through Figure 7 show the four possible signals of SPI_CLK corresponding to each mode. Having
four signal options allows the SPI to interface with different types of serial devices. Also shown on the
footnotes in each figure is the SPI_CLK control bit polarity and phase values corresponding to each signal.
Write SPIDAT1
SPI_CLK
1 2 3 4 5 6 7 8
SPI_DO MSB D6 D5 D4 D3 D2 D1 LSB
SPI_DI D7 D6 D5 D4 D3 D2 D1 D0
Sample in
reception
Write SPIDAT1
SPI_CLK
1 2 3 4 5 6 7 8
SPI_DO MSB D6 D5 D4 D3 D2 D1 LSB
SPI_DI D7 D6 D5 D4 D3 D2 D1 D0
Sample in
reception
Peripheral Architecture
Write SPIDAT1
SPI_CLK
1 2 3 4 5 6 7 8
SPI_DO MSB D6 D5 D4 D3 D2 D1 LSB
SPI_DI D7 D6 D5 D4 D3 D2 D1 D0
Sample in
reception
Write SPIDAT1
SPI_CLK
1 2 3 4 5 6 7 8
SPI_DO MSB D6 D5 D4 D3 D2 D1 LSB
SPI_DI D7 D6 D5 D4 D3 D2 D1 D0
Sample in
reception
Clock phase = 1 (SPI_CLK with delay)
− Data is output one-half cycle before the first falling edge of SPI_CLK
and on the subsequent rising edges of SPI_CLK
− Input data is latched on the falling edge of SPI_CLK
Peripheral Architecture
Figure 8 shows an example of an SPI data transfer between two devices using a character length of 5 bits
and the different clock mode scenarios in 4-pin mode.
7 6 5 4 3 7 6 5 4 3
SPI_DO from
master
Clock polarity = 0
Clock phase = 0
Clock polarity = 0
Clock phase = 1
Clock polarity = 1
Clock phase = 0
Clock polarity = 1
Clock phase = 1
SPI_ENx
Peripheral Architecture
2.4.3.2 Holding Chip Selects Active Between Transactions
Some SPI slave devices require that chip selects remain active between transactions, such as serial
EEPROMs that use internal address counters, as long as the chip select is active. The CSHOLD bit
controls whether chip selects remain asserted between transactions or not.
• When CSHOLD = 0, the chip selects are deasserted between transactions.
• When CSHOLD = 1, the chip selects remain asserted between transactions as long as the chip select
information (controlled by the CSNR bits in SPIDAT1) has not changed since the last transaction. If the
chip select information is altered between transactions, the chip select is deasserted even if
CSHOLD = 1.
Peripheral Architecture
SPI_DO
SPISIMO
SPI_DI
MSB LSB SPISOMI
Write to
Write to SPIDAT1
SPICLK
SIMO
SOMI
SPI_DO
SPISIMO
SPI_DI
MSB LSB SPISOMI
Write to SPIDAT1
SPICSCS
SPICLK
SPISIMO
SPISOMI
Peripheral Architecture
2.5 Reset Considerations
This section provides the software and hardware reset considerations.
2.6 Initialization
The following section provides the initialization steps to quickly get the SPI module configured for the two
different pin modes supported.
Peripheral Architecture
2.6.2 4-Pin Mode Initialization
1. Make sure the SPI module is in reset by clearing the RESET bit in the SPI global control register 0
(SPIGCR0) to 0.
2. Remove the SPI peripheral from reset by setting the RESET bit in SPIGCR0 to 1.
3. Enable the CLKMOD and MASTER bits in the SPI global control register 1 (SPIGCR1).
4. Enable the SPI_DI, SPI_DO, and SPI_CLK pins and the necessary chip select pins (SPI_EN0 and
SPI_EN1) by setting the corresponding bits in the SPI pin control register (SPIPC0).
5. Configure the desired data format in the SPI data format register (SPIFMTn).
a. Program the clock prescale value in the PRESCALEn bit.
b. Program the character size in the CHARLENn bit.
c. Set the SPI clock PHASEn and POLARITYn bits.
d. Set the shift direction in the SHIFTDIRn bit.
6. Select the preconfigured data format using the DFSEL bit in the SPI shift register (SPIDAT1).
7. If needed, configure the setup or hold time for the chip select lines using the C2TDELAY or
T2CDELAY bits in the SPI delay register (SPIDELAY).
8. Select the desired chip select number. The CSNR field in SPIDAT1 defines the chip select that shall be
activated during the data transfer. Note that the SPI_ENn signals are active low.
9. Setup the default chip select pin value when chip select lines are inactive using the ENnDEF bits in the
SPI default chip select register (SPIDEF).
10. Enable the desired interrupts, if any, in the SPI interrupt register (SPIINT).
11. Select whether you want the interrupt events mapped to INT0 or INT1 using the selection bits in the
SPI interrupt level register (SPILVL).
12. If using the EDMA to perform the transfers, setup and enable the EDMA channels for transmit or
receive.
13. Enable the SPIENA bit in SPIGCR1.
14. If using the EDMA, set the DMAREQEN bit in SPIINT to 1 initiating the EDMA to start writing to
SPIDAT1; therefore, initiating the data transfer.
15. Data is ready to be transferred using the CPU by writing to SPIDAT1.
Peripheral Architecture
The occurrence of the receive interrupt is recorded in the RXINTFLAG bit in the SPI flag register
(SPIFLG). This flag is cleared by reading SPIBUF, writing a 1 to the RXINTFLAG bit, disabling the receive
interrupt, or a system reset.
Peripheral Architecture
2.9 Power Management
The SPI can be placed in reduced-power modes to conserve power during periods of low activity. The
power management of the SPI is controlled by the processor Power and Sleep Controller (PSC). The PSC
acts as a master controller for power management for all of the peripherals on the device. For detailed
information on power management procedures using the PSC, see the TMS320DM644x DMSoC ARM
Subsystem Reference Guide (SPRUE14).
Since entering a low-power mode has the effect of suspending all state machine activities, care must be
taken when entering such modes to ensure that a valid state is entered when low-power mode is active.
As a result, application software must ensure that a low-power mode is not entered during a transmission
or reception of data.
CAUTION
The internal loop-back self-test mode should not be entered during a normal
data transaction or unpredictable operation may occur.
The internal loop-back self-test mode can be utilized to test the SPI transmit path and receive path. In this
mode, the transmit signal is internally fed back to the receiver and the SPI_DO, SPI_DI, and SPI_CLK
pins are disconnected. For example, the transmitted data is internally transferred to the corresponding
receive buffer while external signals remain unchanged. This mode allows the CPU to write into the
transmit buffer, and check that the receive buffer contains the correct transmit data. If an error occurs the
corresponding error is set within the status field. This capability can be useful during code development
and debug. The loop-back test mode is enabled by setting the LOOPBACK bit in the SPI global control
register 1 (SPIGCR1) to 1.
Registers
3 Registers
Table 3 lists the memory-mapped registers for the SPI. See the device-specific data manual for the
memory address of these registers. All other register offset addresses not listed in Table 3 should be
considered as reserved locations and the register contents should not be modified.
15 1 0
Reserved RESET
R-0 R/W-0
LEGEND: R/W = Read/Write; R = Read only; -n = value after reset
Registers
15 2 1 0
Reserved CLKMOD MASTER
R-0 R/W-0 R/W-0
LEGEND: R/W = Read/Write; R = Read only; -n = value after reset
Registers
3.3 SPI Interrupt Register (SPIINT)
The SPI interrupt register (SPIINT) is shown in Figure 13 and described in Table 6.
15 9 8 7 6 5 4 3 0
Reserved RXINTEN Rsvd OVRNINTEN Rsvd BITERRENA Reserved
R-0 R/W-0 R-0 R/W-0 R-0 R/W-0 R-0
LEGEND: R/W = Read/Write; R = Read only; -n = value after reset
Registers
3.4 SPI Interrupt Level Register (SPILVL)
The SPI interrupt level register (SPILVL) is shown in Figure 14 and described in Table 7.
15 9 8 7 6 5 4 3 0
Reserved RXINTLVL Rsvd OVRNINTLVL Rsvd BITERRLVL Reserved
R-0 R/W-0 R-0 R/W-0 R-0 R/W-0 R-0
LEGEND: R/W = Read/Write; R = Read only; -n = value after reset
Registers
3.5 SPI Flag Register (SPIFLG)
The SPI flag register (SPIFLG) is shown in Figure 15 and described in Table 8.
15 9 8 7 6 5 4 3 0
Reserved RXINTFLAG Rsvd OVRNINTFLG Rsvd BITERRFLG Reserved
R-0 R/W1C-0 R-0 R/W1C-0 R-0 RC-0 R-0
LEGEND: R/W = Read/Write; R = Read only; RC = Read bit to clear; W1C = Write 1 to clear (writing 0 has no effect); -n = value after reset
Registers
3.6 SPI Pin Control Register (SPIPC0)
The SPI pin control register (SPIPC0) is shown in Figure 16 and described in Table 9.
15 12 11 10 9 8 2 1 0
Reserved DIFUN DOFUN CLKFUN Reserved EN1FUN EN0FUN
R-0 R/W-0 R/W-0 R/W-0 R-0 R/W-0 R/W-0
LEGEND: R/W = Read/Write; R = Read only; -n = value after reset
Registers
3.7 SPI Pin Control Register 2 (SPIPC2)
The SPI pin control register 2 (SPIPC2) is shown in Figure 17 and described in Table 10.
15 12 11 10 9 8 2 1 0
Reserved DIDIN DODIN CLKDIN Reserved EN1DIN EN0DIN
R-0 R-x R-x R-x R-0 R-x R-x
LEGEND: R = Read only; -n = value after reset; -x = value is indeterminate after reset
Registers
3.8 SPI Shift Register (SPIDAT1)
The SPI shift register (SPIDAT1) is shown in Figure 18 and described in Table 11.
15 0
SPIDAT1
R/W-0
LEGEND: R/W = Read/Write; R = Read only; -n = value after reset
Registers
3.9 SPI Buffer Register (SPIBUF)
The SPI buffer register (SPIBUF) is shown in Figure 19 and described in Table 12. Reading SPIBUF
clears the OVRNINTFLG and RXINTFLAG bits in the SPI flag register (SPIFLG).
15 0
SPIBUF
R-x
LEGEND: R/W = Read/Write; R = Read only; RC = Read bit to clear; -n = value after reset; -x = value is indeterminate after reset
Registers
3.10 SPI Emulation Register (SPIEMU)
The SPI emulation register (SPIEMU) is shown in Figure 20 and described in Table 13.
15 0
SPIEMU
R-x
LEGEND: R = Read only; -n = value after reset; -x = value is indeterminate after reset
Registers
3.11 SPI Delay Register (SPIDELAY)
The SPI delay register (SPIDELAY) is shown in Figure 21 and described in Table 14.
15 0
Reserved
R/W-0
LEGEND: R/W = Read/Write; R = Read only; -n = value after reset
SCS
CLK
SOMI
SYSCLK5
tC2TDELAY
The setup time value is calculated as:
t C2TDELAY + C2TDELAY ) 2
SYSCLK5
Example: SYSCLK5 = 25 MHz and C2TDELAY = 06h; therefore, tC2TDELAY = 320 ns. When the chip
select signal becomes active, the slave has to prepare data transfer within 320 ns.
23-21 Reserved 0 Reserved. The reserved bit location is always read as 0. A value written to this field has no effect.
20-16 T2CDELAY 0-16h Transmit-end-to-chip-select-inactive-delay. T2CDELAY defines a hold time for the slave device that
delays the chip select deactivation by a multiple of SYSCLK5 clock cycles after the last bit is
transferred. T2CDELAY is configured between 1 and 22 SYSCLK5 clock cycles.
SCS
CLK
SOMI
SYSCLK5
tT2CDELAY
The hold time value is calculated as:
t T2CDELAY + T2CDELAY ) 1
SYSCLK5
Example: SYSCLK5 = 25 MHz and T2CDELAY = 02h; therefore, tT2CDELAY = 120 ns. After the last data
bit is being transferred, the chip select signal is held active for 120 ns.
15-0 Reserved 0 Reserved. The reserved bit location is always read as 0. This field must be written with zeroes.
Registers
15 2 1 0
Reserved EN1DEF EN0DEF
R-0 R/W-1 R/W-1
LEGEND: R/W = Read/Write; R = Read only; -n = value after reset
Table 15. SPI Default Chip Select Register (SPIDEF) Field Descriptions
Bit Field Value Description
31-2 Reserved 0 Reserved. The reserved bit location is always read as 0. A value written to this field has no effect.
1 EN1DEF Chip select default pattern. Selects the output to the slave 1 chip select pin (SPI_EN1) when no
transmission is currently in progress. EN1DEF allows you to set a chip select pattern that deselects all
the SPI slaves.
0 SPI_EN1 is driven to logic 0 when no transaction is in progress.
1 SPI_EN1 is driven to logic 1 when no transaction is in progress.
0 EN0DEF Chip select default pattern. Selects the output to the slave 0 chip select pin (SPI_EN0) when no
transmission is currently in progress. EN0DEF allows you to set a chip select pattern that deselects all
the SPI slaves.
0 SPI_EN0 is driven to logic 0 when no transaction is in progress.
1 SPI_EN0 is driven to logic 1 when no transaction is in progress.
Registers
3.13 SPI Data Format Registers (SPIFMTn)
The SPI data format register (SPIFMT0, SPIFMT1, SPIFMT2, and SPIFMT3) is shown in Figure 23 and
described in Table 16.
15 8 7 5 4 0
PRESCALEn Reserved CHARLENn
R/W-0 R-0 R/W-0
LEGEND: R/W = Read/Write; R = Read only; -n = value after reset
SPI_CLK + SYSCLK5
(PRESCALEn ) 1)
PRESCALEn is only supported for values >1, where the maximum SPI clock rate is SYSCLK5/3.
7-5 Reserved 0 Reserved. The reserved bit location is always read as 0. A value written to this field has no effect.
4-0 CHARLENn 0-1Fh Data word length for data format n. CHARLENn defines the word length for data format n
(n = 1,2,3). Legal values are 2h (data word length = 2 bits) to 10h (data word length = 16 bits).
Other values, such as 0 or 1Fh, are not detected and their effect is indeterminate.
0-1h Not detected and their effect is indeterminate.
2h-10h Data word length is 2 bits to 16 bits.
11h-1Fh Not detected and their effect is indeterminate.
Registers
3.14 SPI Interrupt Vector Register 0 (INTVECT0)
The SPI interrupt vector register 0 (INTVECT0) is shown in Figure 24 and described in Table 17.
15 6 5 1 0
Reserved INTVECT0 Rsvd
R-0 R-0 R-0
LEGEND: R = Read only; -n = value after reset
Registers
3.15 SPI Interrupt Vector Register 1 (INTVECT1)
The SPI interrupt vector register 1 (INTVECT1) is shown in Figure 25 and described in Table 18.
15 6 5 1 0
Reserved INTVECT1 Rsvd
R-0 R-0 R-0
LEGEND: R = Read only; -n = value after reset
Table A-1 lists the changes made since the previous version of this document.
Texas Instruments Incorporated and its subsidiaries (TI) reserve the right to make corrections, modifications,
enhancements, improvements, and other changes to its products and services at any time and to
discontinue any product or service without notice. Customers should obtain the latest relevant information
before placing orders and should verify that such information is current and complete. All products are sold
subject to TI’s terms and conditions of sale supplied at the time of order acknowledgment.
TI warrants performance of its hardware products to the specifications applicable at the time of sale in
accordance with TI’s standard warranty. Testing and other quality control techniques are used to the extent
TI deems necessary to support this warranty. Except where mandated by government requirements, testing
of all parameters of each product is not necessarily performed.
TI assumes no liability for applications assistance or customer product design. Customers are responsible
for their products and applications using TI components. To minimize the risks associated with customer
products and applications, customers should provide adequate design and operating safeguards.
TI does not warrant or represent that any license, either express or implied, is granted under any TI patent
right, copyright, mask work right, or other TI intellectual property right relating to any combination, machine,
or process in which TI products or services are used. Information published by TI regarding third-party
products or services does not constitute a license from TI to use such products or services or a warranty or
endorsement thereof. Use of such information may require a license from a third party under the patents or
other intellectual property of the third party, or a license from TI under the patents or other intellectual
property of TI.
Reproduction of information in TI data books or data sheets is permissible only if reproduction is without
alteration and is accompanied by all associated warranties, conditions, limitations, and notices.
Reproduction of this information with alteration is an unfair and deceptive business practice. TI is not
responsible or liable for such altered documentation.
Resale of TI products or services with statements different from or beyond the parameters stated by TI for
that product or service voids all express and any implied warranties for the associated TI product or service
and is an unfair and deceptive business practice. TI is not responsible or liable for any such statements.
Following are URLs where you can obtain information on other Texas Instruments products and application
solutions:
Products Applications
Amplifiers amplifier.ti.com Audio www.ti.com/audio
Data Converters dataconverter.ti.com Automotive www.ti.com/automotive
DSP dsp.ti.com Broadband www.ti.com/broadband
Interface interface.ti.com Digital Control www.ti.com/digitalcontrol
Logic logic.ti.com Military www.ti.com/military
Power Mgmt power.ti.com Optical Networking www.ti.com/opticalnetwork
Microcontrollers microcontroller.ti.com Security www.ti.com/security
Low Power Wireless www.ti.com/lpw Telephony www.ti.com/telephony
Video & Imaging www.ti.com/video
Wireless www.ti.com/wireless