160 #include "stm32f4xx_rcc.h" 175 #define CR1_CLEAR_MASK ((uint16_t)0x3040) 176 #define I2SCFGR_CLEAR_MASK ((uint16_t)0xF040) 179 #define PLLCFGR_PPLR_MASK ((uint32_t)0x70000000) 180 #define PLLCFGR_PPLN_MASK ((uint32_t)0x00007FC0) 182 #define SPI_CR2_FRF ((uint16_t)0x0010) 183 #define SPI_SR_TIFRFE ((uint16_t)0x0100) 236 else if (SPIx ==
SPI2)
243 else if (SPIx ==
SPI3)
250 else if (SPIx ==
SPI4)
257 else if (SPIx ==
SPI5)
350 uint16_t tmpreg = 0, i2sdiv = 2, i2sodd = 0, packetlength = 1;
351 uint32_t tmp = 0, i2sclk = 0;
352 #ifndef I2S_EXTERNAL_CLOCK_VAL 353 uint32_t pllm = 0, plln = 0, pllr = 0;
368 SPIx->
I2SPR = 0x0002;
376 i2sodd = (uint16_t)0;
377 i2sdiv = (uint16_t)2;
398 #ifdef I2S_EXTERNAL_CLOCK_VAL 406 i2sclk = I2S_EXTERNAL_CLOCK_VAL;
427 i2sclk = (uint32_t)(((
HSE_VALUE / pllm) * plln) / pllr);
434 tmp = (uint16_t)(((((i2sclk / 256) * 10) / I2S_InitStruct->
I2S_AudioFreq)) + 5);
439 tmp = (uint16_t)(((((i2sclk / (32 * packetlength)) *10 ) / I2S_InitStruct->
I2S_AudioFreq)) + 5);
446 i2sodd = (uint16_t)(tmp & (uint16_t)0x0001);
449 i2sdiv = (uint16_t)((tmp - i2sodd) / 2);
452 i2sodd = (uint16_t) (i2sodd << 8);
456 if ((i2sdiv < 2) || (i2sdiv > 0xFF))
464 SPIx->
I2SPR = (uint16_t)((uint16_t)i2sdiv | (uint16_t)(i2sodd | (uint16_t)I2S_InitStruct->
I2S_MCLKOutput));
469 (uint16_t)I2S_InitStruct->
I2S_CPOL))));
597 SPIx->
CR1 |= SPI_DataSize;
729 uint16_t tmpreg = 0, tmp = 0;
741 I2Sxext->
I2SPR = 0x0002;
763 (uint16_t)I2S_InitStruct->
I2S_CPOL))));
1019 SPIx->
CR2 |= SPI_I2S_DMAReq;
1024 SPIx->
CR2 &= (uint16_t)~SPI_I2S_DMAReq;
1119 uint16_t itpos = 0, itmask = 0 ;
1127 itpos = SPI_I2S_IT >> 4;
1130 itmask = (uint16_t)1 << (uint16_t)itpos;
1135 SPIx->
CR2 |= itmask;
1140 SPIx->
CR2 &= (uint16_t)~itmask;
1169 if ((SPIx->
SR & SPI_I2S_FLAG) != (uint16_t)
RESET)
1209 SPIx->
SR = (uint16_t)~SPI_I2S_FLAG;
1230 uint16_t itpos = 0, itmask = 0, enablestatus = 0;
1237 itpos = 0x01 << (SPI_I2S_IT & 0x0F);
1240 itmask = SPI_I2S_IT >> 4;
1243 itmask = 0x01 << itmask;
1246 enablestatus = (SPIx->
CR2 & itmask) ;
1249 if (((SPIx->
SR & itpos) != (uint16_t)
RESET) && enablestatus)
1290 itpos = 0x01 << (SPI_I2S_IT & 0x0F);
1293 SPIx->
SR = (uint16_t)~itpos;
void I2S_Cmd(SPI_TypeDef *SPIx, FunctionalState NewState)
Enables or disables the specified SPI peripheral (in I2S mode).
#define RCC_APB2Periph_SPI6
#define IS_SPI_NSS_INTERNAL(INTERNAL)
void I2S_Init(SPI_TypeDef *SPIx, I2S_InitTypeDef *I2S_InitStruct)
Initializes the SPIx peripheral according to the specified parameters in the I2S_InitStruct.
void SPI_I2S_DeInit(SPI_TypeDef *SPIx)
De-initialize the SPIx peripheral registers to their default reset values.
#define IS_SPI_I2S_GET_IT(IT)
#define IS_SPI_ALL_PERIPH(PERIPH)
#define RCC_PLLI2SCFGR_PLLI2SN
void SPI_I2S_ClearFlag(SPI_TypeDef *SPIx, uint16_t SPI_I2S_FLAG)
Clears the SPIx CRC Error (CRCERR) flag.
#define IS_SPI_I2S_CLEAR_FLAG(FLAG)
#define I2SCFGR_CLEAR_MASK
#define IS_I2S_AUDIO_FREQ(FREQ)
#define RCC_APB2Periph_SPI4
void SPI_I2S_ITConfig(SPI_TypeDef *SPIx, uint8_t SPI_I2S_IT, FunctionalState NewState)
Enables or disables the specified SPI/I2S interrupts.
#define IS_SPI_I2S_DMAREQ(DMAREQ)
uint16_t SPI_BaudRatePrescaler
void SPI_I2S_DMACmd(SPI_TypeDef *SPIx, uint16_t SPI_I2S_DMAReq, FunctionalState NewState)
Enables or disables the SPIx/I2Sx DMA interface.
This file contains all the functions prototypes for the SPI firmware library.
#define I2S_MCLKOutput_Disable
void SPI_DataSizeConfig(SPI_TypeDef *SPIx, uint16_t SPI_DataSize)
Configures the data size for the selected SPI.
uint16_t SPI_CRCPolynomial
void assert_param(int val)
#define IS_SPI_DIRECTION(DIRECTION)
#define IS_FUNCTIONAL_STATE(STATE)
Serial Peripheral Interface.
#define RCC_APB1Periph_SPI2
#define RCC_APB2Periph_SPI1
uint16_t SPI_GetCRCPolynomial(SPI_TypeDef *SPIx)
Returns the CRC Polynomial register value for the specified SPI.
#define IS_SPI_FIRST_BIT(BIT)
#define RCC_PLLI2SCFGR_PLLI2SR
void SPI_TIModeCmd(SPI_TypeDef *SPIx, FunctionalState NewState)
Enables or disables the SPIx/I2Sx DMA interface.
void RCC_APB1PeriphResetCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)
Forces or releases Low Speed APB (APB1) peripheral reset.
void SPI_BiDirectionalLineConfig(SPI_TypeDef *SPIx, uint16_t SPI_Direction)
Selects the data transfer direction in bidirectional mode for the specified SPI.
#define SPI_NSSInternalSoft_Set
#define IS_I2S_CPOL(CPOL)
void SPI_I2S_SendData(SPI_TypeDef *SPIx, uint16_t Data)
Transmits a Data through the SPIx/I2Sx peripheral.
uint16_t SPI_GetCRC(SPI_TypeDef *SPIx, uint8_t SPI_CRC)
Returns the transmit or the receive CRC register value for the specified SPI.
#define I2S_Mode_MasterTx
#define IS_SPI_DATASIZE(DATASIZE)
#define SPI_BaudRatePrescaler_2
void SPI_TransmitCRC(SPI_TypeDef *SPIx)
Transmit the SPIx CRC value.
#define HSE_VALUE
Comment the line below if you will not use the peripherals drivers. In this case, these drivers will ...
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 ...
#define IS_I2S_MODE(MODE)
SPI Init structure definition.
#define SPI_Direction_2Lines_FullDuplex
void SPI_NSSInternalSoftwareConfig(SPI_TypeDef *SPIx, uint16_t SPI_NSSInternalSoft)
Configures internally by software the NSS pin for the selected SPI.
#define I2S_Mode_MasterRx
#define IS_SPI_MODE(MODE)
void I2S_StructInit(I2S_InitTypeDef *I2S_InitStruct)
Fills each I2S_InitStruct member with its default value.
#define I2S_Standard_Phillips
#define IS_SPI_CPHA(CPHA)
#define SPI_NSSInternalSoft_Reset
#define IS_I2S_STANDARD(STANDARD)
#define IS_SPI_I2S_GET_FLAG(FLAG)
uint16_t SPI_I2S_ReceiveData(SPI_TypeDef *SPIx)
Returns the most recent received data by the SPIx/I2Sx peripheral.
#define IS_SPI_23_PERIPH(PERIPH)
#define IS_SPI_I2S_CONFIG_IT(IT)
void RCC_APB2PeriphResetCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)
Forces or releases High Speed APB (APB2) peripheral reset.
FlagStatus SPI_I2S_GetFlagStatus(SPI_TypeDef *SPIx, uint16_t SPI_I2S_FLAG)
Checks whether the specified SPIx/I2Sx flag is set or not.
void SPI_SSOutputCmd(SPI_TypeDef *SPIx, FunctionalState NewState)
Enables or disables the SS output for the selected SPI.
#define SPI_I2SCFGR_I2SMOD
ITStatus SPI_I2S_GetITStatus(SPI_TypeDef *SPIx, uint8_t SPI_I2S_IT)
Checks whether the specified SPIx/I2Sx interrupt has occurred or not.
#define IS_SPI_CPOL(CPOL)
I2S Init structure definition.
#define IS_SPI_BAUDRATE_PRESCALER(PRESCALER)
#define RCC_APB2Periph_SPI5
#define RCC_APB1Periph_SPI3
#define IS_I2S_EXT_PERIPH(PERIPH)
void SPI_Init(SPI_TypeDef *SPIx, SPI_InitTypeDef *SPI_InitStruct)
Initializes the SPIx peripheral according to the specified parameters in the SPI_InitStruct.
#define I2S_MCLKOutput_Enable
#define IS_SPI_ALL_PERIPH_EXT(PERIPH)
#define IS_SPI_DIRECTION_MODE(MODE)
void SPI_StructInit(SPI_InitTypeDef *SPI_InitStruct)
Fills each SPI_InitStruct member with its default value.
#define IS_I2S_MCLK_OUTPUT(OUTPUT)
#define IS_SPI_CRC_POLYNOMIAL(POLYNOMIAL)
void SPI_CalculateCRC(SPI_TypeDef *SPIx, FunctionalState NewState)
Enables or disables the CRC value calculation of the transferred bytes.
#define IS_SPI_23_PERIPH_EXT(PERIPH)
#define IS_SPI_I2S_CLEAR_IT(IT)
void SPI_Cmd(SPI_TypeDef *SPIx, FunctionalState NewState)
Enables or disables the specified SPI peripheral.
#define I2S_AudioFreq_Default
void SPI_I2S_ClearITPendingBit(SPI_TypeDef *SPIx, uint8_t SPI_I2S_IT)
Clears the SPIx CRC Error (CRCERR) interrupt pending bit.