NuMicro® NUC029LEE/NUC029SEE
32-bit Arm
®
Cortex
®
-M0 Microcontroller
Aug, 2018
Page
428
of
497
Rev 1.00
N
U
MICRO
®
N
UC02
9L
E
E
/N
UC029
S
E
E
T
E
CHN
ICA
L R
E
F
E
R
E
NC
E
M
A
NU
A
L
6.15.7 Programming Examples
Example 1:
The SPI controller is set as a master to access an off-chip slave device with the
following specifications:
Data bit is latched on positive edge of SPI clock.
Data bit is driven on negative edge of SPI clock.
Data is transferred from MSB first.
SPI bus clock is idle at low state.
Only one byte of data to be transmitted/received in a transaction.
Uses the first SPI slave select pin to connect with an off-chip slave device. The slave select
signal is active low.
The operation flow is as follows.
1) Set the DIVIDER (SPI_DIVIDER [7:0]) register to determine the output frequency of SPI
clock.
2) Write the SPI_SSR register a proper value for the related settings of Master mode:
1. Clear the Automatic Slave Selection bit, AUTOSS (SPI_SSR[3]), to 0.
2. Select low level trigger output of slave select signal in the Slave Select Active Level bit,
SS_LVL (SPI_SSR[2]), and Slave Select Level Trigger bit, SS_LTRIG
(SPI_SSR[4]).
3. Select slave select signal to be output active at the I/O pin by setting the Slave Select
Register bit SSR[0] (SPI_SSR[0]) to active the off-chip slave device.
3) Write the related settings into the SPI_CNTRL register to control the SPI master actions
1. Set this SPI controller as master device in SLAVE bit (SPI_CNTRL[18] = 0).
2. Force the SPI clock idle state at low in CLKP bit (SPI_CNTRL[11] = 0).
3. Select data transmitted at negative edge of SPI clock in TX_NEG bit
(SPI_CNTRL[2] = 1).
4. Select data latched at positive edge of SPI clock in RX_NEG bit (SPI_CNTRL[1] = 0).
5. Set the bit length of word transfer as 8-bit in TX_BIT_LEN bit field.
(SPI_CNTRL[7:3] = 0x08).
6. Set MSB transfer first in MSB bit (SPI_CNTRL[10] = 0).
4) If this SPI master attempts to transmit (write) one byte data to the off-chip slave device, write
the byte data that will be transmitted into the SPI_TX0 register.
5) If this SPI master just only attempts to receive (read) one byte data from the off-chip slave
device and does not care what data will be transmitted, the SPI_TX0 register does not need
to be updated by software.
6) Enable the GO_BUSY bit (SPI_CNTRL [0] = 1) to start the data transfer with the SPI
interface.
7) Waiting for SPI interrupt (if the Interrupt Enable IE bit is set) or just polling the GO_BUSY bit
till it is cleared to 0 by hardware automatically.
8) Read out the received one byte data from SPI_RX0[7:0].