EasyManuals Logo

ST STM32F31xx User Manual

ST STM32F31xx
584 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #406 background imageLoading...
Page #406 background image
Serial peripheral interface (SPI)
UM1581
406/584
DocID023800 Rev 1
20.2 SPI Firmware driver API description
The following section lists the various functions of the SPI library.
20.2.1 How to use this driver
1. Enable peripheral clock using RCC_APBPeriphClockCmd(RCC_APB2Periph_SPI1,
ENABLE) function for SPI1 or using
RCC_APBPeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE) function for SPI2.
2. Enable SCK, MOSI, MISO and NSS GPIO clocks using RCC_AHBPeriphClockCmd()
function.
3. Peripherals alternate function:
 Connect the pin to the desired peripherals' Alternate Function (AF) using
GPIO_PinAFConfig() function.
 Configure the desired pin in alternate function by: GPIO_InitStruct->GPIO_Mode
= GPIO_Mode_AF.
 Select the type, pull-up/pull-down and output speed via GPIO_PuPd,
GPIO_OType and GPIO_Speed members.
 Call GPIO_Init() function.
4. Program the Polarity, Phase, First Data, Baud Rate Prescaler, Slave Management,
Peripheral Mode and CRC Polynomial values using the SPI_Init() function in SPI
mode. In I2S mode, program the Mode, Standard, Data Format, MCLK Output, Audio
frequency and Polarity using I2S_Init() function.
5. Configure the FIFO threshold using SPI_RxFIFOThresholdConfig() to select at which
threshold the RXNE event is generated.
6. Enable the NVIC and the corresponding interrupt using the function
SPI_I2S_ITConfig() if you need to use interrupt mode.
7. When using the DMA mode
 Configure the DMA using DMA_Init() function.
 Active the needed channel Request using SPI_I2S_DMACmd() function.
8. Enable the SPI using the SPI_Cmd() function or enable the I2S using I2S_Cmd().
9. Enable the DMA using the DMA_Cmd() function when using DMA mode.
10. Optionally you can enable/configure the following parameters without re-initialization
(i.e there is no need to call again SPI_Init() function):
 When bidirectional mode (SPI_Direction_1Line_Rx or SPI_Direction_1Line_Tx)
is programmed as Data direction parameter using the SPI_Init() function it can be
possible to switch between SPI_Direction_Tx or SPI_Direction_Rx using the
SPI_BiDirectionalLineConfig() function.
 When SPI_NSS_Soft is selected as Slave Select Management parameter using
the SPI_Init() function it can be possible to manage the NSS internal signal using
the SPI_NSSInternalSoftwareConfig() function.
 Reconfigure the data size using the SPI_DataSizeConfig() function.
 Enable or disable the SS output using the SPI_SSOutputCmd() function.
11. To use the CRC Hardware calculation feature refer to the Peripheral CRC hardware
Calculation subsection.
It is possible to use SPI in I2S full duplex mode, in this case, each SPI peripheral is able to
manage sending and receiving data simultaneously using two data lines. Each SPI
peripheral has an extended block called I2Sxext (ie. I2S2ext for SPI2 and I2S3ext for
SPI3). The extension block is not a full SPI IP, it is used only as I2S slave to implement full
duplex mode. The extension block uses the same clock sources as its master. To configure
I2S full duplex you have to:

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the ST STM32F31xx and is the answer not in the manual?

ST STM32F31xx Specifications

General IconGeneral
BrandST
ModelSTM32F31xx
CategoryMicrocontrollers
LanguageEnglish

Related product manuals