Serial peripheral interface (SPI)
RM0090
880/1731
DocID018909 Rev 11
Transmit-only procedure (BIDIMODE=0 RXONLY=0)
In this mode, the procedure can be reduced as described below and the BSY bit can be
used to wait until the completion of the transmission (see
and
).
1.
Enable the SPI by setting the SPE bit to 1.
2. Write the first data item to send into the SPI_DR register (this clears the TXE bit).
3. Wait until TXE=1 and write the next data item to be transmitted. Repeat this step for
each data item to be transmitted.
4. After writing the last data item into the SPI_DR register, wait until TXE=1, then wait until
BSY=0, this indicates that the transmission of the last data is complete.
This procedure can be also implemented using dedicated interrupt subroutines launched at
each rising edge of the TXE flag.
Note:
During discontinuous communications, there is a 2 APB clock period delay between the
write operation to SPI_DR and the BSY bit setting. As a consequence, in transmit-only
mode, it is mandatory to wait first until TXE is set and then until BSY is cleared after writing
the last data.
After transmitting two data items in transmit-only mode, the OVR flag is set in the SPI_SR
register since the received data are never read.
Figure 255. TXE/BSY behavior in Master transmit-only mode (BIDIMODE=0 and RXONLY=0) in
case of continuous transfers
0xF1
Tx b
u
ffer
TXE fl
a
g
0xF2
B
S
Y fl
a
g
0xF
3
software writes
0xF1 into
SPI_DR
software waits
until TXE=1 and
writes 0xF2 into
SPI_DR
s
et by h
a
rdw
a
re
cle
a
red by
s
oftw
a
re
s
et by h
a
rdw
a
re
cle
a
red by
s
oftw
a
re
s
et by h
a
rdw
a
re
s
et by h
a
rdw
a
re
S
CK
re
s
et by h
a
rdw
a
re
Ex
a
mple in M
as
ter mode with CPOL=1, CPHA=1
(write to
S
PI_DR)
MI
S
O/MO
S
I (o
u
t)
DATA 1 = 0xF1
DATA 2 = 0xF2
DATA
3
= 0xF
3
software waits
until TXE=1 and
writes 0xF3 into
SPI_DR
software waits until BSY=0
software waits until TXE=1
b0 b1 b2 b
3
b4 b5 b6 b7 b0 b1 b2 b
3
b4 b5 b6 b7 b0 b1 b2 b
3
b4 b5 b6 b7
a
i17
3
45