29.01.2015 Views

STM32F101xx, STM32F102xx, STM32F103xx, STM32F105xx and ...

STM32F101xx, STM32F102xx, STM32F103xx, STM32F105xx and ...

STM32F101xx, STM32F102xx, STM32F103xx, STM32F105xx and ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

RM0008<br />

Serial peripheral interface (SPI)<br />

23.3.2 SPI slave mode<br />

In slave configuration, the serial clock is received on the SCK pin from the master device.<br />

The value set in the BR[2:0] bits in the SPI_CR1 register, does not affect the data transfer<br />

rate.<br />

Procedure<br />

1. Set the DFF bit to define 8- or 16-bit data frame format<br />

2. Select the CPOL <strong>and</strong> CPHA bits to define one of the four relationships between the<br />

data transfer <strong>and</strong> the serial clock (see Figure 210). For correct data transfer, the CPOL<br />

<strong>and</strong> CPHA bits must be configured in the same way in the slave device <strong>and</strong> the master<br />

device.<br />

3. The frame format (MSB-first or LSB-first depending on the value of the LSBFIRST bit in<br />

the SPI_CR1 register) must be the same as the master device.<br />

4. In Hardware mode (refer to Slave select (NSS) pin management on page 590), the<br />

NSS pin must be connected to a low level signal during the complete byte transmit<br />

sequence. In Software mode, set the SSM bit <strong>and</strong> clear the SSI bit in the SPI_CR1<br />

register.<br />

5. Clear the MSTR bit <strong>and</strong> set the SPE bit (both in the SPI_CR1 register) to assign the<br />

pins to alternate functions.<br />

In this configuration the MOSI pin is a data input <strong>and</strong> the MISO pin is a data output.<br />

Transmit sequence<br />

The data byte is parallel-loaded into the Tx buffer during a write cycle.<br />

The transmit sequence begins when the slave device receives the clock signal <strong>and</strong> the most<br />

significant bit of the data on its MOSI pin. The remaining bits (the 7 bits in 8-bit data frame<br />

format, <strong>and</strong> the 15 bits in 16-bit data frame format) are loaded into the shift-register. The<br />

TXE flag in the SPI_SR register is set on the transfer of data from the Tx Buffer to the shift<br />

register <strong>and</strong> an interrupt is generated if the TXEIE bit in the SPI_CR2 register is set.<br />

Receive sequence<br />

For the receiver, when data transfer is complete:<br />

● The Data in shift register is transferred to Rx Buffer <strong>and</strong> the RXNE flag (SPI_SR<br />

register) is set<br />

● An Interrupt is generated if the RXNEIE bit is set in the SPI_CR2 register.<br />

After the last sampling clock edge the RXNE bit is set, a copy of the data byte received in<br />

the shift register is moved to the Rx buffer. When the SPI_DR register is read, the SPI<br />

peripheral returns this buffered value.<br />

Clearing of the RXNE bit is performed by reading the SPI_DR register.<br />

23.3.3 SPI master mode<br />

In the master configuration, the serial clock is generated on the SCK pin.<br />

Doc ID 13902 Rev 9 593/995

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

Saved successfully!

Ooh no, something went wrong!