STM32F0 Standard Peripheral bibliotheek  1.0
ST Microelectronics standard peripheral bibliotheek documentatie voor de STM32F0 familie
 All Data Structures Files Functions Variables Enumerations Enumerator Groups
stm32f0xx_spi.c File Reference

This file provides firmware functions to manage the following functionalities of the Serial peripheral interface (SPI): More...

#include "stm32f0xx_spi.h"
#include "stm32f0xx_rcc.h"

Macros

#define CR1_CLEAR_MASK   ((uint16_t)0x3040)
 
#define CR1_CLEAR_MASK2   ((uint16_t)0xFFFB)
 
#define CR2_LDMA_MASK   ((uint16_t)0x9FFF)
 
#define I2SCFGR_CLEAR_Mask   ((uint16_t)0xF040)
 

Functions

void SPI_I2S_DeInit (SPI_TypeDef *SPIx)
 Deinitializes the SPIx peripheral registers to their default reset values. More...
 
void SPI_StructInit (SPI_InitTypeDef *SPI_InitStruct)
 Fills each SPI_InitStruct member with its default value. More...
 
void SPI_Init (SPI_TypeDef *SPIx, SPI_InitTypeDef *SPI_InitStruct)
 Initializes the SPIx peripheral according to the specified parameters in the SPI_InitStruct. More...
 
void I2S_StructInit (I2S_InitTypeDef *I2S_InitStruct)
 Fills each I2S_InitStruct member with its default value. More...
 
void I2S_Init (SPI_TypeDef *SPIx, I2S_InitTypeDef *I2S_InitStruct)
 Initializes the SPIx peripheral according to the specified parameters in the I2S_InitStruct. More...
 
void SPI_Cmd (SPI_TypeDef *SPIx, FunctionalState NewState)
 Enables or disables the specified SPI peripheral. More...
 
void SPI_TIModeCmd (SPI_TypeDef *SPIx, FunctionalState NewState)
 Enables or disables the TI Mode. More...
 
void I2S_Cmd (SPI_TypeDef *SPIx, FunctionalState NewState)
 Enables or disables the specified SPI peripheral (in I2S mode). More...
 
void SPI_DataSizeConfig (SPI_TypeDef *SPIx, uint16_t SPI_DataSize)
 Configures the data size for the selected SPI. More...
 
void SPI_RxFIFOThresholdConfig (SPI_TypeDef *SPIx, uint16_t SPI_RxFIFOThreshold)
 Configures the FIFO reception threshold for the selected SPI. More...
 
void SPI_BiDirectionalLineConfig (SPI_TypeDef *SPIx, uint16_t SPI_Direction)
 Selects the data transfer direction in bidirectional mode for the specified SPI. More...
 
void SPI_NSSInternalSoftwareConfig (SPI_TypeDef *SPIx, uint16_t SPI_NSSInternalSoft)
 Configures internally by software the NSS pin for the selected SPI. More...
 
void SPI_SSOutputCmd (SPI_TypeDef *SPIx, FunctionalState NewState)
 Enables or disables the SS output for the selected SPI. More...
 
void SPI_NSSPulseModeCmd (SPI_TypeDef *SPIx, FunctionalState NewState)
 Enables or disables the NSS pulse management mode. More...
 
void SPI_SendData8 (SPI_TypeDef *SPIx, uint8_t Data)
 Transmits a Data through the SPIx/I2Sx peripheral. More...
 
void SPI_I2S_SendData16 (SPI_TypeDef *SPIx, uint16_t Data)
 Transmits a Data through the SPIx/I2Sx peripheral. More...
 
uint8_t SPI_ReceiveData8 (SPI_TypeDef *SPIx)
 Returns the most recent received data by the SPIx/I2Sx peripheral. More...
 
uint16_t SPI_I2S_ReceiveData16 (SPI_TypeDef *SPIx)
 Returns the most recent received data by the SPIx peripheral. More...
 
void SPI_CRCLengthConfig (SPI_TypeDef *SPIx, uint16_t SPI_CRCLength)
 Configures the CRC calculation length for the selected SPI. More...
 
void SPI_CalculateCRC (SPI_TypeDef *SPIx, FunctionalState NewState)
 Enables or disables the CRC value calculation of the transferred bytes. More...
 
void SPI_TransmitCRC (SPI_TypeDef *SPIx)
 Transmit the SPIx CRC value. More...
 
uint16_t SPI_GetCRC (SPI_TypeDef *SPIx, uint8_t SPI_CRC)
 Returns the transmit or the receive CRC register value for the specified SPI. More...
 
uint16_t SPI_GetCRCPolynomial (SPI_TypeDef *SPIx)
 Returns the CRC Polynomial register value for the specified SPI. More...
 
void SPI_I2S_DMACmd (SPI_TypeDef *SPIx, uint16_t SPI_I2S_DMAReq, FunctionalState NewState)
 Enables or disables the SPIx/I2Sx DMA interface. More...
 
void SPI_LastDMATransferCmd (SPI_TypeDef *SPIx, uint16_t SPI_LastDMATransfer)
 Configures the number of data to transfer type(Even/Odd) for the DMA last transfers and for the selected SPI. More...
 
void SPI_I2S_ITConfig (SPI_TypeDef *SPIx, uint8_t SPI_I2S_IT, FunctionalState NewState)
 Enables or disables the specified SPI/I2S interrupts. More...
 
uint16_t SPI_GetTransmissionFIFOStatus (SPI_TypeDef *SPIx)
 Returns the current SPIx Transmission FIFO filled level. More...
 
uint16_t SPI_GetReceptionFIFOStatus (SPI_TypeDef *SPIx)
 Returns the current SPIx Reception FIFO filled level. More...
 
FlagStatus SPI_I2S_GetFlagStatus (SPI_TypeDef *SPIx, uint16_t SPI_I2S_FLAG)
 Checks whether the specified SPI flag is set or not. More...
 
void SPI_I2S_ClearFlag (SPI_TypeDef *SPIx, uint16_t SPI_I2S_FLAG)
 Clears the SPIx CRC Error (CRCERR) flag. More...
 
ITStatus SPI_I2S_GetITStatus (SPI_TypeDef *SPIx, uint8_t SPI_I2S_IT)
 Checks whether the specified SPI/I2S interrupt has occurred or not. More...
 

Detailed Description

This file provides firmware functions to manage the following functionalities of the Serial peripheral interface (SPI):

Author
MCD Application Team
Version
V1.0.1
Date
20-April-2012
  • Initialization and Configuration
  • Data transfers functions
  • Hardware CRC Calculation
  • DMA transfers management
  • Interrupts and flags management
===============================================================================
                      ##### How to use this driver #####
===============================================================================
   [..]
       (#) Enable peripheral clock using RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE)
           function for SPI1 or using RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE)
           function for SPI2.
 
       (#) Enable SCK, MOSI, MISO and NSS GPIO clocks using 
           RCC_AHBPeriphClockCmd() function. 
 
       (#) 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.
 
       (#) Program the Polarity, Phase, First Data, Baud Rate Prescaler, Slave 
           Management, Peripheral Mode and CRC Polynomial values using the SPI_Init()
           function.In I2S mode, program the Mode, Standard, Data Format, MCLK 
           Output, Audio frequency and Polarity using I2S_Init() function.
 
       (#) Enable the NVIC and the corresponding interrupt using the function 
           SPI_ITConfig() if you need to use interrupt mode. 
 
       (#) When using the DMA mode 
           (++) Configure the DMA using DMA_Init() function.
           (++) Active the needed channel Request using SPI_I2S_DMACmd() function.
  
       (#) Enable the SPI using the SPI_Cmd() function or enable the I2S using
           I2S_Cmd().
  
       (#) Enable the DMA using the DMA_Cmd() function when using DMA mode. 
 
       (#) 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.  
 
       (#) To use the CRC Hardware calculation feature refer to the Peripheral 
           CRC hardware Calculation subsection.
Attention

© COPYRIGHT 2012 STMicroelectronics

Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); You may not use this file except in compliance with the License. You may obtain a copy of the License at:

   http://www.st.com/software_license_agreement_liberty_v2

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.