STM32F10x Standard Peripherals Library  3.5.0
/opt/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_spi.h
Go to the documentation of this file.
00001 
00023 /* Define to prevent recursive inclusion -------------------------------------*/
00024 #ifndef __STM32F10x_SPI_H
00025 #define __STM32F10x_SPI_H
00026 
00027 #ifdef __cplusplus
00028  extern "C" {
00029 #endif
00030 
00031 /* Includes ------------------------------------------------------------------*/
00032 #include "stm32f10x.h"
00033 
00050 typedef struct
00051 {
00052   uint16_t SPI_Direction;           
00055   uint16_t SPI_Mode;                
00058   uint16_t SPI_DataSize;            
00061   uint16_t SPI_CPOL;                
00064   uint16_t SPI_CPHA;                
00067   uint16_t SPI_NSS;                 
00071   uint16_t SPI_BaudRatePrescaler;   
00077   uint16_t SPI_FirstBit;            
00080   uint16_t SPI_CRCPolynomial;       
00081 }SPI_InitTypeDef;
00082 
00087 typedef struct
00088 {
00089 
00090   uint16_t I2S_Mode;         
00093   uint16_t I2S_Standard;     
00096   uint16_t I2S_DataFormat;   
00099   uint16_t I2S_MCLKOutput;   
00102   uint32_t I2S_AudioFreq;    
00105   uint16_t I2S_CPOL;         
00107 }I2S_InitTypeDef;
00108 
00117 #define IS_SPI_ALL_PERIPH(PERIPH) (((PERIPH) == SPI1) || \
00118                                    ((PERIPH) == SPI2) || \
00119                                    ((PERIPH) == SPI3))
00120 
00121 #define IS_SPI_23_PERIPH(PERIPH) (((PERIPH) == SPI2) || \
00122                                   ((PERIPH) == SPI3))
00123 
00128 #define SPI_Direction_2Lines_FullDuplex ((uint16_t)0x0000)
00129 #define SPI_Direction_2Lines_RxOnly     ((uint16_t)0x0400)
00130 #define SPI_Direction_1Line_Rx          ((uint16_t)0x8000)
00131 #define SPI_Direction_1Line_Tx          ((uint16_t)0xC000)
00132 #define IS_SPI_DIRECTION_MODE(MODE) (((MODE) == SPI_Direction_2Lines_FullDuplex) || \
00133                                      ((MODE) == SPI_Direction_2Lines_RxOnly) || \
00134                                      ((MODE) == SPI_Direction_1Line_Rx) || \
00135                                      ((MODE) == SPI_Direction_1Line_Tx))
00136 
00144 #define SPI_Mode_Master                 ((uint16_t)0x0104)
00145 #define SPI_Mode_Slave                  ((uint16_t)0x0000)
00146 #define IS_SPI_MODE(MODE) (((MODE) == SPI_Mode_Master) || \
00147                            ((MODE) == SPI_Mode_Slave))
00148 
00156 #define SPI_DataSize_16b                ((uint16_t)0x0800)
00157 #define SPI_DataSize_8b                 ((uint16_t)0x0000)
00158 #define IS_SPI_DATASIZE(DATASIZE) (((DATASIZE) == SPI_DataSize_16b) || \
00159                                    ((DATASIZE) == SPI_DataSize_8b))
00160 
00168 #define SPI_CPOL_Low                    ((uint16_t)0x0000)
00169 #define SPI_CPOL_High                   ((uint16_t)0x0002)
00170 #define IS_SPI_CPOL(CPOL) (((CPOL) == SPI_CPOL_Low) || \
00171                            ((CPOL) == SPI_CPOL_High))
00172 
00180 #define SPI_CPHA_1Edge                  ((uint16_t)0x0000)
00181 #define SPI_CPHA_2Edge                  ((uint16_t)0x0001)
00182 #define IS_SPI_CPHA(CPHA) (((CPHA) == SPI_CPHA_1Edge) || \
00183                            ((CPHA) == SPI_CPHA_2Edge))
00184 
00192 #define SPI_NSS_Soft                    ((uint16_t)0x0200)
00193 #define SPI_NSS_Hard                    ((uint16_t)0x0000)
00194 #define IS_SPI_NSS(NSS) (((NSS) == SPI_NSS_Soft) || \
00195                          ((NSS) == SPI_NSS_Hard))
00196 
00204 #define SPI_BaudRatePrescaler_2         ((uint16_t)0x0000)
00205 #define SPI_BaudRatePrescaler_4         ((uint16_t)0x0008)
00206 #define SPI_BaudRatePrescaler_8         ((uint16_t)0x0010)
00207 #define SPI_BaudRatePrescaler_16        ((uint16_t)0x0018)
00208 #define SPI_BaudRatePrescaler_32        ((uint16_t)0x0020)
00209 #define SPI_BaudRatePrescaler_64        ((uint16_t)0x0028)
00210 #define SPI_BaudRatePrescaler_128       ((uint16_t)0x0030)
00211 #define SPI_BaudRatePrescaler_256       ((uint16_t)0x0038)
00212 #define IS_SPI_BAUDRATE_PRESCALER(PRESCALER) (((PRESCALER) == SPI_BaudRatePrescaler_2) || \
00213                                               ((PRESCALER) == SPI_BaudRatePrescaler_4) || \
00214                                               ((PRESCALER) == SPI_BaudRatePrescaler_8) || \
00215                                               ((PRESCALER) == SPI_BaudRatePrescaler_16) || \
00216                                               ((PRESCALER) == SPI_BaudRatePrescaler_32) || \
00217                                               ((PRESCALER) == SPI_BaudRatePrescaler_64) || \
00218                                               ((PRESCALER) == SPI_BaudRatePrescaler_128) || \
00219                                               ((PRESCALER) == SPI_BaudRatePrescaler_256))
00220 
00228 #define SPI_FirstBit_MSB                ((uint16_t)0x0000)
00229 #define SPI_FirstBit_LSB                ((uint16_t)0x0080)
00230 #define IS_SPI_FIRST_BIT(BIT) (((BIT) == SPI_FirstBit_MSB) || \
00231                                ((BIT) == SPI_FirstBit_LSB))
00232 
00240 #define I2S_Mode_SlaveTx                ((uint16_t)0x0000)
00241 #define I2S_Mode_SlaveRx                ((uint16_t)0x0100)
00242 #define I2S_Mode_MasterTx               ((uint16_t)0x0200)
00243 #define I2S_Mode_MasterRx               ((uint16_t)0x0300)
00244 #define IS_I2S_MODE(MODE) (((MODE) == I2S_Mode_SlaveTx) || \
00245                            ((MODE) == I2S_Mode_SlaveRx) || \
00246                            ((MODE) == I2S_Mode_MasterTx) || \
00247                            ((MODE) == I2S_Mode_MasterRx) )
00248 
00256 #define I2S_Standard_Phillips           ((uint16_t)0x0000)
00257 #define I2S_Standard_MSB                ((uint16_t)0x0010)
00258 #define I2S_Standard_LSB                ((uint16_t)0x0020)
00259 #define I2S_Standard_PCMShort           ((uint16_t)0x0030)
00260 #define I2S_Standard_PCMLong            ((uint16_t)0x00B0)
00261 #define IS_I2S_STANDARD(STANDARD) (((STANDARD) == I2S_Standard_Phillips) || \
00262                                    ((STANDARD) == I2S_Standard_MSB) || \
00263                                    ((STANDARD) == I2S_Standard_LSB) || \
00264                                    ((STANDARD) == I2S_Standard_PCMShort) || \
00265                                    ((STANDARD) == I2S_Standard_PCMLong))
00266 
00274 #define I2S_DataFormat_16b              ((uint16_t)0x0000)
00275 #define I2S_DataFormat_16bextended      ((uint16_t)0x0001)
00276 #define I2S_DataFormat_24b              ((uint16_t)0x0003)
00277 #define I2S_DataFormat_32b              ((uint16_t)0x0005)
00278 #define IS_I2S_DATA_FORMAT(FORMAT) (((FORMAT) == I2S_DataFormat_16b) || \
00279                                     ((FORMAT) == I2S_DataFormat_16bextended) || \
00280                                     ((FORMAT) == I2S_DataFormat_24b) || \
00281                                     ((FORMAT) == I2S_DataFormat_32b))
00282 
00290 #define I2S_MCLKOutput_Enable           ((uint16_t)0x0200)
00291 #define I2S_MCLKOutput_Disable          ((uint16_t)0x0000)
00292 #define IS_I2S_MCLK_OUTPUT(OUTPUT) (((OUTPUT) == I2S_MCLKOutput_Enable) || \
00293                                     ((OUTPUT) == I2S_MCLKOutput_Disable))
00294 
00302 #define I2S_AudioFreq_192k               ((uint32_t)192000)
00303 #define I2S_AudioFreq_96k                ((uint32_t)96000)
00304 #define I2S_AudioFreq_48k                ((uint32_t)48000)
00305 #define I2S_AudioFreq_44k                ((uint32_t)44100)
00306 #define I2S_AudioFreq_32k                ((uint32_t)32000)
00307 #define I2S_AudioFreq_22k                ((uint32_t)22050)
00308 #define I2S_AudioFreq_16k                ((uint32_t)16000)
00309 #define I2S_AudioFreq_11k                ((uint32_t)11025)
00310 #define I2S_AudioFreq_8k                 ((uint32_t)8000)
00311 #define I2S_AudioFreq_Default            ((uint32_t)2)
00312 
00313 #define IS_I2S_AUDIO_FREQ(FREQ) ((((FREQ) >= I2S_AudioFreq_8k) && \
00314                                   ((FREQ) <= I2S_AudioFreq_192k)) || \
00315                                  ((FREQ) == I2S_AudioFreq_Default))
00316 
00324 #define I2S_CPOL_Low                    ((uint16_t)0x0000)
00325 #define I2S_CPOL_High                   ((uint16_t)0x0008)
00326 #define IS_I2S_CPOL(CPOL) (((CPOL) == I2S_CPOL_Low) || \
00327                            ((CPOL) == I2S_CPOL_High))
00328 
00336 #define SPI_I2S_DMAReq_Tx               ((uint16_t)0x0002)
00337 #define SPI_I2S_DMAReq_Rx               ((uint16_t)0x0001)
00338 #define IS_SPI_I2S_DMAREQ(DMAREQ) ((((DMAREQ) & (uint16_t)0xFFFC) == 0x00) && ((DMAREQ) != 0x00))
00339 
00347 #define SPI_NSSInternalSoft_Set         ((uint16_t)0x0100)
00348 #define SPI_NSSInternalSoft_Reset       ((uint16_t)0xFEFF)
00349 #define IS_SPI_NSS_INTERNAL(INTERNAL) (((INTERNAL) == SPI_NSSInternalSoft_Set) || \
00350                                        ((INTERNAL) == SPI_NSSInternalSoft_Reset))
00351 
00359 #define SPI_CRC_Tx                      ((uint8_t)0x00)
00360 #define SPI_CRC_Rx                      ((uint8_t)0x01)
00361 #define IS_SPI_CRC(CRC) (((CRC) == SPI_CRC_Tx) || ((CRC) == SPI_CRC_Rx))
00362 
00370 #define SPI_Direction_Rx                ((uint16_t)0xBFFF)
00371 #define SPI_Direction_Tx                ((uint16_t)0x4000)
00372 #define IS_SPI_DIRECTION(DIRECTION) (((DIRECTION) == SPI_Direction_Rx) || \
00373                                      ((DIRECTION) == SPI_Direction_Tx))
00374 
00382 #define SPI_I2S_IT_TXE                  ((uint8_t)0x71)
00383 #define SPI_I2S_IT_RXNE                 ((uint8_t)0x60)
00384 #define SPI_I2S_IT_ERR                  ((uint8_t)0x50)
00385 #define IS_SPI_I2S_CONFIG_IT(IT) (((IT) == SPI_I2S_IT_TXE) || \
00386                                  ((IT) == SPI_I2S_IT_RXNE) || \
00387                                  ((IT) == SPI_I2S_IT_ERR))
00388 #define SPI_I2S_IT_OVR                  ((uint8_t)0x56)
00389 #define SPI_IT_MODF                     ((uint8_t)0x55)
00390 #define SPI_IT_CRCERR                   ((uint8_t)0x54)
00391 #define I2S_IT_UDR                      ((uint8_t)0x53)
00392 #define IS_SPI_I2S_CLEAR_IT(IT) (((IT) == SPI_IT_CRCERR))
00393 #define IS_SPI_I2S_GET_IT(IT) (((IT) == SPI_I2S_IT_RXNE) || ((IT) == SPI_I2S_IT_TXE) || \
00394                                ((IT) == I2S_IT_UDR) || ((IT) == SPI_IT_CRCERR) || \
00395                                ((IT) == SPI_IT_MODF) || ((IT) == SPI_I2S_IT_OVR))
00396 
00404 #define SPI_I2S_FLAG_RXNE               ((uint16_t)0x0001)
00405 #define SPI_I2S_FLAG_TXE                ((uint16_t)0x0002)
00406 #define I2S_FLAG_CHSIDE                 ((uint16_t)0x0004)
00407 #define I2S_FLAG_UDR                    ((uint16_t)0x0008)
00408 #define SPI_FLAG_CRCERR                 ((uint16_t)0x0010)
00409 #define SPI_FLAG_MODF                   ((uint16_t)0x0020)
00410 #define SPI_I2S_FLAG_OVR                ((uint16_t)0x0040)
00411 #define SPI_I2S_FLAG_BSY                ((uint16_t)0x0080)
00412 #define IS_SPI_I2S_CLEAR_FLAG(FLAG) (((FLAG) == SPI_FLAG_CRCERR))
00413 #define IS_SPI_I2S_GET_FLAG(FLAG) (((FLAG) == SPI_I2S_FLAG_BSY) || ((FLAG) == SPI_I2S_FLAG_OVR) || \
00414                                    ((FLAG) == SPI_FLAG_MODF) || ((FLAG) == SPI_FLAG_CRCERR) || \
00415                                    ((FLAG) == I2S_FLAG_UDR) || ((FLAG) == I2S_FLAG_CHSIDE) || \
00416                                    ((FLAG) == SPI_I2S_FLAG_TXE) || ((FLAG) == SPI_I2S_FLAG_RXNE))
00417 
00425 #define IS_SPI_CRC_POLYNOMIAL(POLYNOMIAL) ((POLYNOMIAL) >= 0x1)
00426 
00446 void SPI_I2S_DeInit(SPI_TypeDef* SPIx);
00447 void SPI_Init(SPI_TypeDef* SPIx, SPI_InitTypeDef* SPI_InitStruct);
00448 void I2S_Init(SPI_TypeDef* SPIx, I2S_InitTypeDef* I2S_InitStruct);
00449 void SPI_StructInit(SPI_InitTypeDef* SPI_InitStruct);
00450 void I2S_StructInit(I2S_InitTypeDef* I2S_InitStruct);
00451 void SPI_Cmd(SPI_TypeDef* SPIx, FunctionalState NewState);
00452 void I2S_Cmd(SPI_TypeDef* SPIx, FunctionalState NewState);
00453 void SPI_I2S_ITConfig(SPI_TypeDef* SPIx, uint8_t SPI_I2S_IT, FunctionalState NewState);
00454 void SPI_I2S_DMACmd(SPI_TypeDef* SPIx, uint16_t SPI_I2S_DMAReq, FunctionalState NewState);
00455 void SPI_I2S_SendData(SPI_TypeDef* SPIx, uint16_t Data);
00456 uint16_t SPI_I2S_ReceiveData(SPI_TypeDef* SPIx);
00457 void SPI_NSSInternalSoftwareConfig(SPI_TypeDef* SPIx, uint16_t SPI_NSSInternalSoft);
00458 void SPI_SSOutputCmd(SPI_TypeDef* SPIx, FunctionalState NewState);
00459 void SPI_DataSizeConfig(SPI_TypeDef* SPIx, uint16_t SPI_DataSize);
00460 void SPI_TransmitCRC(SPI_TypeDef* SPIx);
00461 void SPI_CalculateCRC(SPI_TypeDef* SPIx, FunctionalState NewState);
00462 uint16_t SPI_GetCRC(SPI_TypeDef* SPIx, uint8_t SPI_CRC);
00463 uint16_t SPI_GetCRCPolynomial(SPI_TypeDef* SPIx);
00464 void SPI_BiDirectionalLineConfig(SPI_TypeDef* SPIx, uint16_t SPI_Direction);
00465 FlagStatus SPI_I2S_GetFlagStatus(SPI_TypeDef* SPIx, uint16_t SPI_I2S_FLAG);
00466 void SPI_I2S_ClearFlag(SPI_TypeDef* SPIx, uint16_t SPI_I2S_FLAG);
00467 ITStatus SPI_I2S_GetITStatus(SPI_TypeDef* SPIx, uint8_t SPI_I2S_IT);
00468 void SPI_I2S_ClearITPendingBit(SPI_TypeDef* SPIx, uint8_t SPI_I2S_IT);
00469 
00470 #ifdef __cplusplus
00471 }
00472 #endif
00473 
00474 #endif /*__STM32F10x_SPI_H */
00475 
00487 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/