Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
84
Добавлен:
01.03.2016
Размер:
3.56 Mб
Скачать

Serial peripheral interface (SPI)

RM0016

 

 

Figure 97. TXE/BSY in slave transmit-only mode (BDM = 0 and RXONLY = 0). Case of continuous transfers

Example in slave mode with CPOL=1, CPHA=1

 

 

 

 

 

 

 

SCK

 

 

 

 

 

 

 

 

 

 

 

 

 

DATA 1 = 0xF1

 

DATA 2 = 0xF2

 

 

DATA 3 = 0xF3

 

 

MISO/MOSI (out)

b0 b1

b2 b3 b4 b5 b6 b7

b0

b1 b2 b3 b4 b5 b6

b7 b0

b1

b2 b3 b4 b5

b6

b7

 

 

 

set by hw

 

set by hw

 

 

 

 

 

TXE flag

 

 

cleared by sw

 

cleared by sw

 

 

set by hw

 

 

Tx Buffer

 

0xF1

0xF2

 

0xF3

 

 

 

 

 

(write SPI_DR)

 

 

 

 

 

 

 

 

 

 

BSY flag

 

set by hw

 

 

 

 

 

 

reset by hw

software writes

software waits

software waits

 

 

 

 

 

 

0xF1 in SPI_DR

until TXE=1 and

until TXE=1 and

software waits until TXE=1

software waits until BSY=0

 

 

writes 0xF2 in

writes 0xF3 in

 

 

 

 

 

 

 

 

 

 

SPI_DR

SPI_DR

 

 

 

 

 

 

 

Bidirectional transmit procedure (BDM = 1 and BDOE = 1)

In this mode, the procedure is similar to the Transmit-only procedure except that the BDM and BDOE bits must both be set in the SPI_CR2 register before enabling the SPI.

Unidirectional receive-only procedure (BDM = 0 and RXONLY = 1)

In this mode, the procedure can be reduced as described below (see Figure 98):

1.Set the RXONLY bit in the SPI_CR2 register

2.Enable the SPI by setting bit SPE to 1:

a)In master mode, this immediately activates the generation of the SCK clock, and data is received serially until the SPI is disabled (SPE = 0).

b)In slave mode, data are received when the SPI master device drives NSS low and generates the SCK clock.

3.Wait until RXNE =1 and read the SPI_DR register to get the received data (this clears the RXNE bit). Repeat this operation for each data to be received.

This procedure can be also implemented using dedicated interrupt subroutines launched at each rising edge of the RXNE flag.

Note:

If it is required to disable the SPI after the last transfer, follow the recommendation described

 

in Section 20.3.8: Disabling the SPI on page 268.

264/454

Doc ID 14587 Rev 9

RM0016

Serial peripheral interface (SPI)

 

 

Figure 98. RXNE behavior in receive-only mode (BDM = 0 and RXONLY = 1). Case of continuous transfers

Example with CPOL=1, CPHA=1, RXONLY=1

SCK

MISO/MOSI (in)

RXNE flag

Rx Buffer

(read SPI_DR)

 

 

DATA 1 = 0xA1

 

 

 

 

DATA 2 = 0xA2

 

 

 

DATA 3 = 0xA3

 

 

b0

b1

b2

b3

b4

b5

b6

b7

b0

b1

b2

b3

b4

b5

b6

b7 b0

b1

b2

b3

b4

b5

b6

b7

 

 

 

 

set by hw

 

cleared by sw

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0xA1

 

 

 

 

 

0xA2

 

 

 

 

 

0xA3

software waits until RXNE=1

 

software waits until RXNE=1

 

software waits until RXNE=1

and reads 0xA1 from SPI_DR

 

and reads 0xA2 from SPI_DR

 

and reads 0xA3 from SPI_DR

 

 

 

 

 

Bidirectional receive procedure (BDM = 1 and BDOE = 0)

In this mode, the procedure is similar to the Receive-only procedure except that the BDM bit must be set and the BDOE bit must be reset in the SPI_CR2 register before enabling the SPI.

Continuous and discontinuous transfers

When transmitting data in master mode, if the software is fast enough to detect each TXE rising edge (or TXE interrupt) and to immediately write the SPI_DR register before the ongoing data transfer is complete, the communication is said to be continuous. In this case, there is no discontinuity in the generation of the SPI clock between each data and the BSY bit will never be reset between each data transfer.

On the contrary, if the software is not fast enough, this can lead to some discontinuities in the communication. In this case, the BSY bit is reset between each data transmission (see

Figure 99).

In master receive-only mode (BDM = 0 and RXONLY = 1) or in bidirectional receive mode (BDM = 1 and BDOE = 0), the communication is always continuous and the BSY flag is always read at 1.

In slave mode, the continuity of the communication is decided by the SPI master device. But even if the communication is continuous, the BSY flag goes low between each transfer for a minimum duration of one SPI clock cycle (see Figure 95).

Doc ID 14587 Rev 9

265/454

Соседние файлы в папке Минимум документации STM8