09.12.2012 Views

RM0090: Reference manual - STMicroelectronics

RM0090: Reference manual - STMicroelectronics

RM0090: Reference manual - STMicroelectronics

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.

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

Procedure<br />

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

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

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

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

device. This step is not required when the TI mode is selected through the FRF bit in<br />

the SPI_CR2 register.<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. This step is not required<br />

when TI mode is selected.<br />

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

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

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

register. This step is not required when TI mode is selected.<br />

5. Set the FRF bit in the SPI_CR2 register to select the TI mode protocol for serial<br />

communications.<br />

6. Clear the MSTR bit and 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 and 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 and 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, and 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 and 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 and 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 />

SPI TI protocol in slave mode<br />

In slave mode, the SPI interface is compatible with the TI protocol. The FRF bit of the<br />

SPI_CR2 register can be used to configure the slave SPI serial communications to be<br />

compliant with this protocol.<br />

The clock polarity and phase are forced to conform to the TI protocol requirements whatever<br />

the values set in the SPI_CR1 register. NSS management is also specific to the TI protocol<br />

which makes the configuration of NSS management through the SPI_CR1 and SPI_CR2<br />

registers (such as SSM, SSI, SSOE) transparent for the user.<br />

797/1416 Doc ID 018909 Rev 3

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

Saved successfully!

Ooh no, something went wrong!