29.01.2015 Views

STM32F101xx, STM32F102xx, STM32F103xx, STM32F105xx and ...

STM32F101xx, STM32F102xx, STM32F103xx, STM32F105xx and ...

STM32F101xx, STM32F102xx, STM32F103xx, STM32F105xx and ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

RM0008<br />

Serial peripheral interface (SPI)<br />

communication. The transfer direction (Input/Output) is selected by the BIDIOE bit in the<br />

SPI_CR1 register. When this bit is 1, the data line is output otherwise it is input.<br />

1 clock <strong>and</strong> 1 data wire (receive-only in full-duplex mode)<br />

In order to free an I/O pin so it can be used for other purposes, it is possible to disable the<br />

SPI output function by setting the RXONLY bit in the SPI_CR1 register. In this case, SPI will<br />

function in Receive-only mode. When the RXONLY bit is reset, the SPI will function in full<br />

duplex mode.<br />

To start the communication in receive-only mode, it is necessary to enable the SPI. In the<br />

master mode, the communication starts immediately <strong>and</strong> will stop when the SPE bit is reset<br />

<strong>and</strong> the current reception terminates. In slave mode, the SPI will continue to receive as long<br />

as the NSS is pulled down (or the SSI bit is reset) <strong>and</strong> the SCK is running.<br />

Note:<br />

The SPI can be used in Tx-only mode when the RXONLY bit in the SPI_CR1 register is<br />

reset, the RX pin (MISO in master or MOSI in slave) can be used as GPIO. In this case,<br />

when the data register is read, it does not contain the received value.<br />

In simplex communications, when the SPI master is in Receive-only mode, the clock is<br />

generated continuously once the SPI master has been enabled.<br />

23.3.5 Status flags<br />

Three status flags are provided for the application to completely monitor the state of the SPI<br />

bus.<br />

BUSY flag<br />

Note:<br />

This flag indicates the state of the SPI communication layer. When it is set, it indicates that<br />

the SPI is busy communicating <strong>and</strong>/or there is a valid data byte in the Tx buffer waiting to be<br />

transmitted. The purpose of this flag is to indicate if there is any communication ongoing on<br />

the SPI bus or not. This flag is set as soon as:<br />

1. Data is written in the SPI_DR register in master mode<br />

2. The SCK clock is present in slave mode<br />

The BUSY flag is reset each time a byte is transmitted/received. This flag is set <strong>and</strong> cleared<br />

by hardware. It can be monitored to avoid write collision errors. Writing to this flag has no<br />

effect. The BUSY flag is meaningful only when the SPE bit is set.<br />

In master receiver mode (1-line bidirectional), the BUSY flag must NOT be checked.<br />

Tx buffer empty flag (TXE)<br />

When it is set, this flag indicates that the Tx buffer is empty <strong>and</strong> the next data to be<br />

transmitted can be loaded into the buffer. The TXE flag is reset when the Tx buffer already<br />

contains data to be transmitted. This flag is reset when the SPI is disabled (SPE bit is reset).<br />

Rx buffer not empty (RXNE)<br />

When set, this flag indicates that there are valid received data in the Rx Buffer. It is reset<br />

when SPI Data register is read.<br />

23.3.6 CRC calculation<br />

A CRC calculator has been implemented for communication reliability. Separate CRC<br />

calculators are implemented for transmitted data <strong>and</strong> received data. The CRC is calculated<br />

Doc ID 13902 Rev 9 595/995

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

Saved successfully!

Ooh no, something went wrong!