09.12.2012 Views

RM0090: Reference manual - STMicroelectronics

RM0090: Reference manual - STMicroelectronics

RM0090: Reference manual - STMicroelectronics

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Serial peripheral interface (SPI) <strong>RM0090</strong><br />

Transmit-only procedure (BIDIMODE=0 RXONLY=0)<br />

In this mode, the procedure can be reduced as described below and the BSY bit can be<br />

used to wait until the completion of the transmission (see Figure 279 and Figure 280).<br />

1. Enable the SPI by setting the SPE bit to 1.<br />

2. Write the first data item to send into the SPI_DR register (this clears the TXE bit).<br />

3. Wait until TXE=1 and write the next data item to be transmitted. Repeat this step for<br />

each data item to be transmitted.<br />

4. After writing the last data item into the SPI_DR register, wait until TXE=1, then wait until<br />

BSY=0, this indicates that the transmission of the last data is complete.<br />

This procedure can be also implemented using dedicated interrupt subroutines launched at<br />

each rising edge of the TXE flag.<br />

Note: During discontinuous communications, there is a 2 APB clock period delay between the<br />

write operation to SPI_DR and the BSY bit setting. As a consequence, in transmit-only<br />

mode, it is mandatory to wait first until TXE is set and then until BSY is cleared after writing<br />

the last data.<br />

After transmitting two data items in transmit-only mode, the OVR flag is set in the SPI_SR<br />

register since the received data are never read.<br />

Figure 279. TXE/BSY behavior in Master transmit-only mode (BIDIMODE=0 and RXONLY=0) in the<br />

case of continuous transfers<br />

Example in Master mode with CPOL=1, CPHA=1<br />

SCK<br />

MISO/MOSI (out)<br />

TXE flag<br />

Tx buffer<br />

(write to SPI_DR)<br />

BSY flag<br />

software writes<br />

0xF1 into<br />

SPI_DR<br />

0xF1<br />

software waits<br />

until TXE=1 and<br />

writes 0xF2 into<br />

SPI_DR<br />

DATA 1 = 0xF1 DATA 2 = 0xF2 DATA 3 = 0xF3<br />

b0 b1 b2 b3 b4 b5 b6 b7 b0 b1 b2 b3 b4 b5 b6 b7 b0 b1 b2 b3 b4 b5 b6 b7<br />

set by hardware<br />

set by hardware<br />

cleared by software cleared by software<br />

set by hardware<br />

0xF2<br />

set by hardware<br />

software waits<br />

until TXE=1 and<br />

writes 0xF3 into<br />

SPI_DR<br />

805/1416 Doc ID 018909 Rev 3<br />

0xF3<br />

software waits until TXE=1<br />

software waits until BSY=0<br />

reset by hardware<br />

ai17345

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!