SPI — Serial peripheral interface master

The SPI master provides a simple CPU interface which includes a TXD register for sending data and an RXD register for receiving data. This section is added for legacy support for now.

Figure 1. SPI master

RXD-1 and TXD+1 illustrate the double buffered version of RXD and TXD respectively.

Functional description

The TXD and RXD registers are double-buffered to enable some degree of uninterrupted data flow in and out of the SPI master.

The SPI master does not implement support for chip select directly. Therefore, the CPU must use available GPIOs to select the correct slave and control this independently of the SPI master. The SPI master supports SPI modes 0 through 3.

Table 1. SPI modes
ModeClock polarityClock phase
 CPOLCPHA
SPI_MODE00 (Leading)0 (Active High)
SPI_MODE10 (Leading)1 (Active Low)
SPI_MODE21 (Trailing)0 (Active High)
SPI_MODE31 (Trailing)1 (Active Low)

SPI master mode pin configuration

The different signals SCK, MOSI, and MISO associated with the SPI master are mapped to physical pins.

This mapping is according to the configuration specified in the PSELSCK, PSELMOSI, and PSELMISO registers respectively. If a value of 0xFFFFFFFF is specified in any of these registers, the associated SPI master signal is not connected to any physical pin. The PSELSCK, PSELMOSI, and PSELMISO registers and their configurations are only used as long as the SPI master is enabled, and retained only as long as the device is in ON mode. PSELSCK, PSELMOSI, and PSELMISO must only be configured when the SPI master is disabled.

To secure correct behavior in the SPI, the pins used by the SPI must be configured in the GPIO peripheral as described in Table 2 prior to enabling the SPI. The SCK must always be connected to a pin, and that pin's input buffer must always be connected for the SPI to work. This configuration must be retained in the GPIO for the selected IOs as long as the SPI is enabled.

Only one peripheral can be assigned to drive a particular GPIO pin at a time, failing to do so may result in unpredictable behavior.

Table 2. GPIO configuration
SPI master signalSPI master pinDirectionOutput value
SCKAs specified in PSELSCKOutputSame as CONFIG.CPOL
MOSIAs specified in PSELMOSIOutput0
MISOAs specified in PSELMISOInputNot applicable

Shared resources

The SPI shares registers and other resources with other peripherals that have the same ID as the SPI. Therefore, the user must disable all peripherals that have the same ID as the SPI before the SPI can be configured and used.

Disabling a peripheral that has the same ID as the SPI will not reset any of the registers that are shared with the SPI. It is therefore important to configure all relevant SPI registers explicitly to secure that it operates correctly.

See the Instantiation table in Instantiation for details on peripherals and their IDs.

SPI master transaction sequence

An SPI master transaction is started by writing the first byte, which is to be transmitted by the SPI master, to the TXD register.

Since the transmitter is double buffered, the second byte can be written to the TXD register immediately after the first one. The SPI master will then send these bytes in the order they are written to the TXD register.

The SPI master is a synchronous interface, and for every byte that is sent, a different byte will be received at the same time; this is illustrated in Figure 2. Bytes that are received will be moved to the RXD register where the CPU can extract them by reading the register. The RXD register is double buffered in the same way as the TXD register, and a second byte can therefore be received at the same time as the first byte is being extracted from RXD by the CPU. The SPI master will generate a READY event every time a new byte is moved to the RXD register. The double buffered byte will be moved from RXD-1 to RXD as soon as the first byte is extracted from RXD. The SPI master will stop when there are no more bytes to send in TXD and TXD+1.

Figure 2. SPI master transaction

The READY event of the third byte transaction is delayed until B is extracted from RXD in occurrence number 3 on the horizontal lifeline. The reason for this is that the third event is generated first when C is moved from RXD-1 to RXD after B is read.

The SPI master will move the incoming byte to the RXD register after a short delay following the SCK clock period of the last bit in the byte. This also means that the READY event will be delayed accordingly, see Figure 3. Therefore, it is important that you always clear the READY event, even if the RXD register and the data that is being received is not used.

Figure 3. SPI master transaction

Registers

Table 3. Instances
Base addressPeripheralInstanceDescriptionConfiguration
0x40003000SPISPI0SPI master 0 Deprecated
0x40004000SPISPI1SPI master 1 Deprecated
0x40023000SPISPI2SPI master 2 Deprecated
Table 4. Register Overview
RegisterOffsetDescription
EVENTS_READY0x108TXD byte sent and RXD byte received 
INTENSET0x304Enable interrupt 
INTENCLR0x308Disable interrupt 
ENABLE0x500Enable SPI 
PSELSCK0x508Pin select for SCKDeprecated
PSELMOSI0x50CPin select for MOSIDeprecated
PSELMISO0x510Pin select for MISODeprecated
PSEL.SCK0x508Pin select for SCK 
PSEL.MOSI0x50CPin select for MOSI 
PSEL.MISO0x510Pin select for MISO 
RXD0x518RXD register 
TXD0x51CTXD register 
FREQUENCY0x524SPI frequency 
CONFIG0x554Configuration register 

INTENSET

Address offset: 0x304

Enable interrupt

Bit number313029282726252423222120191817161514131211109876543210
Id                             A  
Reset 0x0000000000000000000000000000000000000000
IdRWFieldValue IdValueDescription
ARWREADY  

Write '1' to Enable interrupt for READY event

See EVENTS_READY

   Set1Enable
   Disabled0Read: Disabled
   Enabled1Read: Enabled
 

INTENCLR

Address offset: 0x308

Disable interrupt

Bit number313029282726252423222120191817161514131211109876543210
Id                             A  
Reset 0x0000000000000000000000000000000000000000
IdRWFieldValue IdValueDescription
ARWREADY  

Write '1' to Disable interrupt for READY event

See EVENTS_READY

   Clear1Disable
   Disabled0Read: Disabled
   Enabled1Read: Enabled
 

ENABLE

Address offset: 0x500

Enable SPI

Bit number313029282726252423222120191817161514131211109876543210
Id                            AAAA
Reset 0x0000000000000000000000000000000000000000
IdRWFieldValue IdValueDescription
ARWENABLE  Enable or disable SPI
   Disabled0Disable SPI
   Enabled1Enable SPI
 

PSELSCK ( Deprecated )

Address offset: 0x508

Pin select for SCK

Bit number313029282726252423222120191817161514131211109876543210
IdAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Reset 0xFFFFFFFF11111111111111111111111111111111
IdRWFieldValue IdValueDescription
ARWPSELSCK [0..31]Pin number configuration for SPI SCK signal
   Disconnected0xFFFFFFFFDisconnect
 

PSELMOSI ( Deprecated )

Address offset: 0x50C

Pin select for MOSI

Bit number313029282726252423222120191817161514131211109876543210
IdAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Reset 0xFFFFFFFF11111111111111111111111111111111
IdRWFieldValue IdValueDescription
ARWPSELMOSI [0..31]Pin number configuration for SPI MOSI signal
   Disconnected0xFFFFFFFFDisconnect
 

PSELMISO ( Deprecated )

Address offset: 0x510

Pin select for MISO

Bit number313029282726252423222120191817161514131211109876543210
IdAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Reset 0xFFFFFFFF11111111111111111111111111111111
IdRWFieldValue IdValueDescription
ARWPSELMISO [0..31]Pin number configuration for SPI MISO signal
   Disconnected0xFFFFFFFFDisconnect
 

PSEL.SCK

Address offset: 0x508

Pin select for SCK

Bit number313029282726252423222120191817161514131211109876543210
IdAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Reset 0xFFFFFFFF11111111111111111111111111111111
IdRWFieldValue IdValueDescription
ARWPSELSCK [0..31]Pin number configuration for SPI SCK signal
   Disconnected0xFFFFFFFFDisconnect
 

PSEL.MOSI

Address offset: 0x50C

Pin select for MOSI

Bit number313029282726252423222120191817161514131211109876543210
IdAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Reset 0xFFFFFFFF11111111111111111111111111111111
IdRWFieldValue IdValueDescription
ARWPSELMOSI [0..31]Pin number configuration for SPI MOSI signal
   Disconnected0xFFFFFFFFDisconnect
 

PSEL.MISO

Address offset: 0x510

Pin select for MISO

Bit number313029282726252423222120191817161514131211109876543210
IdAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Reset 0xFFFFFFFF11111111111111111111111111111111
IdRWFieldValue IdValueDescription
ARWPSELMISO [0..31]Pin number configuration for SPI MISO signal
   Disconnected0xFFFFFFFFDisconnect
 

RXD

Address offset: 0x518

RXD register

Bit number313029282726252423222120191817161514131211109876543210
Id                        AAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IdRWFieldValue IdValueDescription
ARRXD  RX data received. Double buffered
 

TXD

Address offset: 0x51C

TXD register

Bit number313029282726252423222120191817161514131211109876543210
Id                        AAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IdRWFieldValue IdValueDescription
ARWTXD  TX data to send. Double buffered
 

FREQUENCY

Address offset: 0x524

SPI frequency

Bit number313029282726252423222120191817161514131211109876543210
IdAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Reset 0x0400000000000100000000000000000000000000
IdRWFieldValue IdValueDescription
ARWFREQUENCY  SPI master data rate
   K1250x02000000125 kbps
   K2500x04000000250 kbps
   K5000x08000000500 kbps
   M10x100000001 Mbps
   M20x200000002 Mbps
   M40x400000004 Mbps
   M80x800000008 Mbps
 

CONFIG

Address offset: 0x554

Configuration register

Bit number313029282726252423222120191817161514131211109876543210
Id                             CBA
Reset 0x0000000000000000000000000000000000000000
IdRWFieldValue IdValueDescription
ARWORDER  Bit order
   MsbFirst0Most significant bit shifted out first
   LsbFirst1Least significant bit shifted out first
BRWCPHA  Serial clock (SCK) phase
   Leading0Sample on leading edge of clock, shift serial data on trailing edge
   Trailing1Sample on trailing edge of clock, shift serial data on leading edge
CRWCPOL  Serial clock (SCK) polarity
   ActiveHigh0Active high
   ActiveLow1Active low
 

Electrical specification

SPI master interface

SymbolDescriptionMin.Typ.Max.Units
fSPIBit rates for SPI182Mbps
ISPI,2MbpsRun current for SPI, 2 Mbps50µA
ISPI,8MbpsRun current for SPI, 8 Mbps50µA
ISPI,IDLEIdle current for SPI (STARTed, no CSN activity)<1µA
tSPI,START,LPTime from writing TXD register to transmission started, low power modetSPI,START,CL + tSTART_HFINTµs
tSPI,START,CLTime from writing TXD register to transmission started, constant latency mode1µs

Serial Peripheral Interface (SPI) Master timing specifications

SymbolDescriptionMin.Typ.Max.Units
tSPI,CSCK,8MbpsSCK period at 8Mbps125ns
tSPI,CSCK,4MbpsSCK period at 4Mbps250ns
tSPI,CSCK,2MbpsSCK period at 2Mbps500ns
tSPI,RSCK,LDSCK rise time, low driveatRF,25pF 
tSPI,RSCK,HDSCK rise time, high driveatHRF,25pF 
tSPI,FSCK,LDSCK fall time, low driveatRF,25pF 
tSPI,FSCK,HDSCK fall time, high driveatHRF,25pF 
tSPI,WHSCKSCK high timea(0.5*tCSCK) – tRSCK 
tSPI,WLSCKSCK low timea(0.5*tCSCK) – tFSCK 
tSPI,SUMIMISO to CLK edge setup time19ns
tSPI,HMICLK edge to MISO hold time18ns
tSPI,VMOCLK edge to MOSI valid59ns
tSPI,HMOMOSI hold time after CLK edge20ns
Figure 4. SPI master timing diagram
1 Higher bit rates may require GPIOs to be set as High Drive, see GPIO chapter for more details.
2 The actual maximum data rate depends on the slave's CLK to MISO and MOSI setup and hold timings.
a At 25pF load, including GPIO capacitance, see GPIO spec.