30 #ifndef __STM32F4xx_SPI_H 31 #define __STM32F4xx_SPI_H 119 #define IS_SPI_ALL_PERIPH(PERIPH) (((PERIPH) == SPI1) || \ 120 ((PERIPH) == SPI2) || \ 121 ((PERIPH) == SPI3) || \ 122 ((PERIPH) == SPI4) || \ 123 ((PERIPH) == SPI5) || \ 126 #define IS_SPI_ALL_PERIPH_EXT(PERIPH) (((PERIPH) == SPI1) || \ 127 ((PERIPH) == SPI2) || \ 128 ((PERIPH) == SPI3) || \ 129 ((PERIPH) == SPI4) || \ 130 ((PERIPH) == SPI5) || \ 131 ((PERIPH) == SPI6) || \ 132 ((PERIPH) == I2S2ext) || \ 133 ((PERIPH) == I2S3ext)) 135 #define IS_SPI_23_PERIPH(PERIPH) (((PERIPH) == SPI2) || \ 138 #define IS_SPI_23_PERIPH_EXT(PERIPH) (((PERIPH) == SPI2) || \ 139 ((PERIPH) == SPI3) || \ 140 ((PERIPH) == I2S2ext) || \ 141 ((PERIPH) == I2S3ext)) 143 #define IS_I2S_EXT_PERIPH(PERIPH) (((PERIPH) == I2S2ext) || \ 144 ((PERIPH) == I2S3ext)) 151 #define SPI_Direction_2Lines_FullDuplex ((uint16_t)0x0000) 152 #define SPI_Direction_2Lines_RxOnly ((uint16_t)0x0400) 153 #define SPI_Direction_1Line_Rx ((uint16_t)0x8000) 154 #define SPI_Direction_1Line_Tx ((uint16_t)0xC000) 155 #define IS_SPI_DIRECTION_MODE(MODE) (((MODE) == SPI_Direction_2Lines_FullDuplex) || \ 156 ((MODE) == SPI_Direction_2Lines_RxOnly) || \ 157 ((MODE) == SPI_Direction_1Line_Rx) || \ 158 ((MODE) == SPI_Direction_1Line_Tx)) 167 #define SPI_Mode_Master ((uint16_t)0x0104) 168 #define SPI_Mode_Slave ((uint16_t)0x0000) 169 #define IS_SPI_MODE(MODE) (((MODE) == SPI_Mode_Master) || \ 170 ((MODE) == SPI_Mode_Slave)) 179 #define SPI_DataSize_16b ((uint16_t)0x0800) 180 #define SPI_DataSize_8b ((uint16_t)0x0000) 181 #define IS_SPI_DATASIZE(DATASIZE) (((DATASIZE) == SPI_DataSize_16b) || \ 182 ((DATASIZE) == SPI_DataSize_8b)) 191 #define SPI_CPOL_Low ((uint16_t)0x0000) 192 #define SPI_CPOL_High ((uint16_t)0x0002) 193 #define IS_SPI_CPOL(CPOL) (((CPOL) == SPI_CPOL_Low) || \ 194 ((CPOL) == SPI_CPOL_High)) 203 #define SPI_CPHA_1Edge ((uint16_t)0x0000) 204 #define SPI_CPHA_2Edge ((uint16_t)0x0001) 205 #define IS_SPI_CPHA(CPHA) (((CPHA) == SPI_CPHA_1Edge) || \ 206 ((CPHA) == SPI_CPHA_2Edge)) 215 #define SPI_NSS_Soft ((uint16_t)0x0200) 216 #define SPI_NSS_Hard ((uint16_t)0x0000) 217 #define IS_SPI_NSS(NSS) (((NSS) == SPI_NSS_Soft) || \ 218 ((NSS) == SPI_NSS_Hard)) 227 #define SPI_BaudRatePrescaler_2 ((uint16_t)0x0000) 228 #define SPI_BaudRatePrescaler_4 ((uint16_t)0x0008) 229 #define SPI_BaudRatePrescaler_8 ((uint16_t)0x0010) 230 #define SPI_BaudRatePrescaler_16 ((uint16_t)0x0018) 231 #define SPI_BaudRatePrescaler_32 ((uint16_t)0x0020) 232 #define SPI_BaudRatePrescaler_64 ((uint16_t)0x0028) 233 #define SPI_BaudRatePrescaler_128 ((uint16_t)0x0030) 234 #define SPI_BaudRatePrescaler_256 ((uint16_t)0x0038) 235 #define IS_SPI_BAUDRATE_PRESCALER(PRESCALER) (((PRESCALER) == SPI_BaudRatePrescaler_2) || \ 236 ((PRESCALER) == SPI_BaudRatePrescaler_4) || \ 237 ((PRESCALER) == SPI_BaudRatePrescaler_8) || \ 238 ((PRESCALER) == SPI_BaudRatePrescaler_16) || \ 239 ((PRESCALER) == SPI_BaudRatePrescaler_32) || \ 240 ((PRESCALER) == SPI_BaudRatePrescaler_64) || \ 241 ((PRESCALER) == SPI_BaudRatePrescaler_128) || \ 242 ((PRESCALER) == SPI_BaudRatePrescaler_256)) 251 #define SPI_FirstBit_MSB ((uint16_t)0x0000) 252 #define SPI_FirstBit_LSB ((uint16_t)0x0080) 253 #define IS_SPI_FIRST_BIT(BIT) (((BIT) == SPI_FirstBit_MSB) || \ 254 ((BIT) == SPI_FirstBit_LSB)) 263 #define I2S_Mode_SlaveTx ((uint16_t)0x0000) 264 #define I2S_Mode_SlaveRx ((uint16_t)0x0100) 265 #define I2S_Mode_MasterTx ((uint16_t)0x0200) 266 #define I2S_Mode_MasterRx ((uint16_t)0x0300) 267 #define IS_I2S_MODE(MODE) (((MODE) == I2S_Mode_SlaveTx) || \ 268 ((MODE) == I2S_Mode_SlaveRx) || \ 269 ((MODE) == I2S_Mode_MasterTx)|| \ 270 ((MODE) == I2S_Mode_MasterRx)) 280 #define I2S_Standard_Phillips ((uint16_t)0x0000) 281 #define I2S_Standard_MSB ((uint16_t)0x0010) 282 #define I2S_Standard_LSB ((uint16_t)0x0020) 283 #define I2S_Standard_PCMShort ((uint16_t)0x0030) 284 #define I2S_Standard_PCMLong ((uint16_t)0x00B0) 285 #define IS_I2S_STANDARD(STANDARD) (((STANDARD) == I2S_Standard_Phillips) || \ 286 ((STANDARD) == I2S_Standard_MSB) || \ 287 ((STANDARD) == I2S_Standard_LSB) || \ 288 ((STANDARD) == I2S_Standard_PCMShort) || \ 289 ((STANDARD) == I2S_Standard_PCMLong)) 298 #define I2S_DataFormat_16b ((uint16_t)0x0000) 299 #define I2S_DataFormat_16bextended ((uint16_t)0x0001) 300 #define I2S_DataFormat_24b ((uint16_t)0x0003) 301 #define I2S_DataFormat_32b ((uint16_t)0x0005) 302 #define IS_I2S_DATA_FORMAT(FORMAT) (((FORMAT) == I2S_DataFormat_16b) || \ 303 ((FORMAT) == I2S_DataFormat_16bextended) || \ 304 ((FORMAT) == I2S_DataFormat_24b) || \ 305 ((FORMAT) == I2S_DataFormat_32b)) 314 #define I2S_MCLKOutput_Enable ((uint16_t)0x0200) 315 #define I2S_MCLKOutput_Disable ((uint16_t)0x0000) 316 #define IS_I2S_MCLK_OUTPUT(OUTPUT) (((OUTPUT) == I2S_MCLKOutput_Enable) || \ 317 ((OUTPUT) == I2S_MCLKOutput_Disable)) 326 #define I2S_AudioFreq_192k ((uint32_t)192000) 327 #define I2S_AudioFreq_96k ((uint32_t)96000) 328 #define I2S_AudioFreq_48k ((uint32_t)48000) 329 #define I2S_AudioFreq_44k ((uint32_t)44100) 330 #define I2S_AudioFreq_32k ((uint32_t)32000) 331 #define I2S_AudioFreq_22k ((uint32_t)22050) 332 #define I2S_AudioFreq_16k ((uint32_t)16000) 333 #define I2S_AudioFreq_11k ((uint32_t)11025) 334 #define I2S_AudioFreq_8k ((uint32_t)8000) 335 #define I2S_AudioFreq_Default ((uint32_t)2) 337 #define IS_I2S_AUDIO_FREQ(FREQ) ((((FREQ) >= I2S_AudioFreq_8k) && \ 338 ((FREQ) <= I2S_AudioFreq_192k)) || \ 339 ((FREQ) == I2S_AudioFreq_Default)) 348 #define I2S_CPOL_Low ((uint16_t)0x0000) 349 #define I2S_CPOL_High ((uint16_t)0x0008) 350 #define IS_I2S_CPOL(CPOL) (((CPOL) == I2S_CPOL_Low) || \ 351 ((CPOL) == I2S_CPOL_High)) 360 #define SPI_I2S_DMAReq_Tx ((uint16_t)0x0002) 361 #define SPI_I2S_DMAReq_Rx ((uint16_t)0x0001) 362 #define IS_SPI_I2S_DMAREQ(DMAREQ) ((((DMAREQ) & (uint16_t)0xFFFC) == 0x00) && ((DMAREQ) != 0x00)) 371 #define SPI_NSSInternalSoft_Set ((uint16_t)0x0100) 372 #define SPI_NSSInternalSoft_Reset ((uint16_t)0xFEFF) 373 #define IS_SPI_NSS_INTERNAL(INTERNAL) (((INTERNAL) == SPI_NSSInternalSoft_Set) || \ 374 ((INTERNAL) == SPI_NSSInternalSoft_Reset)) 383 #define SPI_CRC_Tx ((uint8_t)0x00) 384 #define SPI_CRC_Rx ((uint8_t)0x01) 385 #define IS_SPI_CRC(CRC) (((CRC) == SPI_CRC_Tx) || ((CRC) == SPI_CRC_Rx)) 394 #define SPI_Direction_Rx ((uint16_t)0xBFFF) 395 #define SPI_Direction_Tx ((uint16_t)0x4000) 396 #define IS_SPI_DIRECTION(DIRECTION) (((DIRECTION) == SPI_Direction_Rx) || \ 397 ((DIRECTION) == SPI_Direction_Tx)) 406 #define SPI_I2S_IT_TXE ((uint8_t)0x71) 407 #define SPI_I2S_IT_RXNE ((uint8_t)0x60) 408 #define SPI_I2S_IT_ERR ((uint8_t)0x50) 409 #define I2S_IT_UDR ((uint8_t)0x53) 410 #define SPI_I2S_IT_TIFRFE ((uint8_t)0x58) 412 #define IS_SPI_I2S_CONFIG_IT(IT) (((IT) == SPI_I2S_IT_TXE) || \ 413 ((IT) == SPI_I2S_IT_RXNE) || \ 414 ((IT) == SPI_I2S_IT_ERR)) 416 #define SPI_I2S_IT_OVR ((uint8_t)0x56) 417 #define SPI_IT_MODF ((uint8_t)0x55) 418 #define SPI_IT_CRCERR ((uint8_t)0x54) 420 #define IS_SPI_I2S_CLEAR_IT(IT) (((IT) == SPI_IT_CRCERR)) 422 #define IS_SPI_I2S_GET_IT(IT) (((IT) == SPI_I2S_IT_RXNE)|| ((IT) == SPI_I2S_IT_TXE) || \ 423 ((IT) == SPI_IT_CRCERR) || ((IT) == SPI_IT_MODF) || \ 424 ((IT) == SPI_I2S_IT_OVR) || ((IT) == I2S_IT_UDR) ||\ 425 ((IT) == SPI_I2S_IT_TIFRFE)) 434 #define SPI_I2S_FLAG_RXNE ((uint16_t)0x0001) 435 #define SPI_I2S_FLAG_TXE ((uint16_t)0x0002) 436 #define I2S_FLAG_CHSIDE ((uint16_t)0x0004) 437 #define I2S_FLAG_UDR ((uint16_t)0x0008) 438 #define SPI_FLAG_CRCERR ((uint16_t)0x0010) 439 #define SPI_FLAG_MODF ((uint16_t)0x0020) 440 #define SPI_I2S_FLAG_OVR ((uint16_t)0x0040) 441 #define SPI_I2S_FLAG_BSY ((uint16_t)0x0080) 442 #define SPI_I2S_FLAG_TIFRFE ((uint16_t)0x0100) 444 #define IS_SPI_I2S_CLEAR_FLAG(FLAG) (((FLAG) == SPI_FLAG_CRCERR)) 445 #define IS_SPI_I2S_GET_FLAG(FLAG) (((FLAG) == SPI_I2S_FLAG_BSY) || ((FLAG) == SPI_I2S_FLAG_OVR) || \ 446 ((FLAG) == SPI_FLAG_MODF) || ((FLAG) == SPI_FLAG_CRCERR) || \ 447 ((FLAG) == I2S_FLAG_UDR) || ((FLAG) == I2S_FLAG_CHSIDE) || \ 448 ((FLAG) == SPI_I2S_FLAG_TXE) || ((FLAG) == SPI_I2S_FLAG_RXNE)|| \ 449 ((FLAG) == SPI_I2S_FLAG_TIFRFE)) 458 #define IS_SPI_CRC_POLYNOMIAL(POLYNOMIAL) ((POLYNOMIAL) >= 0x1) 467 #define SPI_DMAReq_Tx SPI_I2S_DMAReq_Tx 468 #define SPI_DMAReq_Rx SPI_I2S_DMAReq_Rx 469 #define SPI_IT_TXE SPI_I2S_IT_TXE 470 #define SPI_IT_RXNE SPI_I2S_IT_RXNE 471 #define SPI_IT_ERR SPI_I2S_IT_ERR 472 #define SPI_IT_OVR SPI_I2S_IT_OVR 473 #define SPI_FLAG_RXNE SPI_I2S_FLAG_RXNE 474 #define SPI_FLAG_TXE SPI_I2S_FLAG_TXE 475 #define SPI_FLAG_OVR SPI_I2S_FLAG_OVR 476 #define SPI_FLAG_BSY SPI_I2S_FLAG_BSY 477 #define SPI_DeInit SPI_I2S_DeInit 478 #define SPI_ITConfig SPI_I2S_ITConfig 479 #define SPI_DMACmd SPI_I2S_DMACmd 480 #define SPI_SendData SPI_I2S_SendData 481 #define SPI_ReceiveData SPI_I2S_ReceiveData 482 #define SPI_GetFlagStatus SPI_I2S_GetFlagStatus 483 #define SPI_ClearFlag SPI_I2S_ClearFlag 484 #define SPI_GetITStatus SPI_I2S_GetITStatus 485 #define SPI_ClearITPendingBit SPI_I2S_ClearITPendingBit
void I2S_Init(SPI_TypeDef *SPIx, I2S_InitTypeDef *I2S_InitStruct)
Initializes the SPIx peripheral according to the specified parameters in the I2S_InitStruct.
uint16_t SPI_I2S_ReceiveData(SPI_TypeDef *SPIx)
Returns the most recent received data by the SPIx/I2Sx peripheral.
void I2S_StructInit(I2S_InitTypeDef *I2S_InitStruct)
Fills each I2S_InitStruct member with its default value.
uint16_t SPI_BaudRatePrescaler
uint16_t SPI_CRCPolynomial
void SPI_I2S_DeInit(SPI_TypeDef *SPIx)
Deinitializes the SPIx peripheral registers to their default reset values.
void SPI_I2S_ITConfig(SPI_TypeDef *SPIx, uint8_t SPI_I2S_IT, FunctionalState NewState)
Enables or disables the specified SPI/I2S interrupts.
void SPI_TransmitCRC(SPI_TypeDef *SPIx)
Transmits the SPIx CRC value.
CMSIS Cortex-M4 Device Peripheral Access Layer Header File. This file contains all the peripheral reg...
ITStatus SPI_I2S_GetITStatus(SPI_TypeDef *SPIx, uint8_t SPI_I2S_IT)
Checks whether the specified SPI/I2S interrupt has occurred or not.
void I2S_FullDuplexConfig(SPI_TypeDef *I2Sxext, I2S_InitTypeDef *I2S_InitStruct)
Configures the full duplex mode for the I2Sx peripheral using its extension I2Sxext according to the ...
FlagStatus SPI_I2S_GetFlagStatus(SPI_TypeDef *SPIx, uint16_t SPI_I2S_FLAG)
Checks whether the specified SPI flag is set or not.
Serial Peripheral Interface.
void SPI_I2S_ClearITPendingBit(SPI_TypeDef *SPIx, uint8_t SPI_I2S_IT)
Clears the SPIx CRC Error (CRCERR) interrupt pending bit.
void SPI_I2S_ClearFlag(SPI_TypeDef *SPIx, uint16_t SPI_I2S_FLAG)
Clears the SPIx CRC Error (CRCERR) flag.
void SPI_CalculateCRC(SPI_TypeDef *SPIx, FunctionalState NewState)
Enables or disables the CRC value calculation of the transferred bytes.
uint16_t SPI_GetCRC(SPI_TypeDef *SPIx, uint8_t SPI_CRC)
Returns the transmit or the receive CRC register value for the specified SPI.
void SPI_DataSizeConfig(SPI_TypeDef *SPIx, uint16_t SPI_DataSize)
Configures the data size for the selected SPI.
void SPI_SSOutputCmd(SPI_TypeDef *SPIx, FunctionalState NewState)
Enables or disables the SS output for the selected SPI.
void SPI_I2S_DMACmd(SPI_TypeDef *SPIx, uint16_t SPI_I2S_DMAReq, FunctionalState NewState)
Enables or disables the SPIx/I2Sx DMA interface.
SPI Init structure definition.
void SPI_Cmd(SPI_TypeDef *SPIx, FunctionalState NewState)
Enables or disables the specified SPI peripheral.
void SPI_Init(SPI_TypeDef *SPIx, SPI_InitTypeDef *SPI_InitStruct)
Initializes the SPIx peripheral according to the specified parameters in the SPI_InitStruct.
void SPI_StructInit(SPI_InitTypeDef *SPI_InitStruct)
Fills each SPI_InitStruct member with its default value.
void I2S_Cmd(SPI_TypeDef *SPIx, FunctionalState NewState)
Enables or disables the specified SPI peripheral (in I2S mode).
uint16_t SPI_GetCRCPolynomial(SPI_TypeDef *SPIx)
Returns the CRC Polynomial register value for the specified SPI.
void SPI_NSSInternalSoftwareConfig(SPI_TypeDef *SPIx, uint16_t SPI_NSSInternalSoft)
Configures internally by software the NSS pin for the selected SPI.
I2S Init structure definition.
void SPI_I2S_SendData(SPI_TypeDef *SPIx, uint16_t Data)
Transmits a Data through the SPIx/I2Sx peripheral.
void SPI_BiDirectionalLineConfig(SPI_TypeDef *SPIx, uint16_t SPI_Direction)
Selects the data transfer direction in bidirectional mode for the specified SPI.
void SPI_TIModeCmd(SPI_TypeDef *SPIx, FunctionalState NewState)
Enables or disables the TI Mode.