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)
227 assert_param(IS_SPI_ALL_PERIPH(SPIx));
236 else if (SPIx == SPI2)
243 else if (SPIx == SPI3)
250 else if (SPIx == SPI4)
257 else if (SPIx == SPI5)
289 assert_param(IS_SPI_ALL_PERIPH(SPIx));
292 assert_param(IS_SPI_DIRECTION_MODE(SPI_InitStruct->
SPI_Direction));
293 assert_param(IS_SPI_MODE(SPI_InitStruct->
SPI_Mode));
294 assert_param(IS_SPI_DATASIZE(SPI_InitStruct->
SPI_DataSize));
295 assert_param(IS_SPI_CPOL(SPI_InitStruct->
SPI_CPOL));
296 assert_param(IS_SPI_CPHA(SPI_InitStruct->
SPI_CPHA));
297 assert_param(IS_SPI_NSS(SPI_InitStruct->
SPI_NSS));
299 assert_param(IS_SPI_FIRST_BIT(SPI_InitStruct->
SPI_FirstBit));
323 SPIx->I2SCFGR &= (uint16_t)~((uint16_t)SPI_I2SCFGR_I2SMOD);
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;
357 assert_param(IS_SPI_23_PERIPH(SPIx));
358 assert_param(IS_I2S_MODE(I2S_InitStruct->
I2S_Mode));
359 assert_param(IS_I2S_STANDARD(I2S_InitStruct->
I2S_Standard));
362 assert_param(IS_I2S_AUDIO_FREQ(I2S_InitStruct->
I2S_AudioFreq));
363 assert_param(IS_I2S_CPOL(I2S_InitStruct->
I2S_CPOL));
367 SPIx->I2SCFGR &= I2SCFGR_CLEAR_MASK;
368 SPIx->I2SPR = 0x0002;
371 tmpreg = SPIx->I2SCFGR;
376 i2sodd = (uint16_t)0;
377 i2sdiv = (uint16_t)2;
398 #ifdef I2S_EXTERNAL_CLOCK_VAL
400 if ((RCC->CFGR & RCC_CFGR_I2SSRC) == 0)
402 RCC->CFGR |= (uint32_t)RCC_CFGR_I2SSRC;
406 i2sclk = I2S_EXTERNAL_CLOCK_VAL;
410 if ((RCC->CFGR & RCC_CFGR_I2SSRC) != 0)
412 RCC->CFGR &= ~(uint32_t)RCC_CFGR_I2SSRC;
416 plln = (uint32_t)(((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SN) >> 6) & \
417 (RCC_PLLI2SCFGR_PLLI2SN >> 6));
420 pllr = (uint32_t)(((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SR) >> 28) & \
421 (RCC_PLLI2SCFGR_PLLI2SR >> 28));
424 pllm = (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM);
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));
467 tmpreg |= (uint16_t)((uint16_t)SPI_I2SCFGR_I2SMOD | (uint16_t)(I2S_InitStruct->
I2S_Mode | \
469 (uint16_t)I2S_InitStruct->
I2S_CPOL))));
472 SPIx->I2SCFGR = tmpreg;
484 SPI_InitStruct->
SPI_Direction = SPI_Direction_2Lines_FullDuplex;
486 SPI_InitStruct->
SPI_Mode = SPI_Mode_Slave;
490 SPI_InitStruct->
SPI_CPOL = SPI_CPOL_Low;
492 SPI_InitStruct->
SPI_CPHA = SPI_CPHA_1Edge;
494 SPI_InitStruct->
SPI_NSS = SPI_NSS_Hard;
512 I2S_InitStruct->
I2S_Mode = I2S_Mode_SlaveTx;
527 I2S_InitStruct->
I2S_CPOL = I2S_CPOL_Low;
537 void SPI_Cmd(SPI_TypeDef* SPIx, FunctionalState NewState)
540 assert_param(IS_SPI_ALL_PERIPH(SPIx));
541 assert_param(IS_FUNCTIONAL_STATE(NewState));
542 if (NewState != DISABLE)
545 SPIx->CR1 |= SPI_CR1_SPE;
550 SPIx->CR1 &= (uint16_t)~((uint16_t)SPI_CR1_SPE);
562 void I2S_Cmd(SPI_TypeDef* SPIx, FunctionalState NewState)
565 assert_param(IS_SPI_23_PERIPH_EXT(SPIx));
566 assert_param(IS_FUNCTIONAL_STATE(NewState));
568 if (NewState != DISABLE)
571 SPIx->I2SCFGR |= SPI_I2SCFGR_I2SE;
576 SPIx->I2SCFGR &= (uint16_t)~((uint16_t)SPI_I2SCFGR_I2SE);
592 assert_param(IS_SPI_ALL_PERIPH(SPIx));
593 assert_param(IS_SPI_DATASIZE(SPI_DataSize));
595 SPIx->CR1 &= (uint16_t)~SPI_DataSize_16b;
597 SPIx->CR1 |= SPI_DataSize;
612 assert_param(IS_SPI_ALL_PERIPH(SPIx));
613 assert_param(IS_SPI_DIRECTION(SPI_Direction));
614 if (SPI_Direction == SPI_Direction_Tx)
617 SPIx->CR1 |= SPI_Direction_Tx;
622 SPIx->CR1 &= SPI_Direction_Rx;
638 assert_param(IS_SPI_ALL_PERIPH(SPIx));
639 assert_param(IS_SPI_NSS_INTERNAL(SPI_NSSInternalSoft));
640 if (SPI_NSSInternalSoft != SPI_NSSInternalSoft_Reset)
643 SPIx->CR1 |= SPI_NSSInternalSoft_Set;
648 SPIx->CR1 &= SPI_NSSInternalSoft_Reset;
662 assert_param(IS_SPI_ALL_PERIPH(SPIx));
663 assert_param(IS_FUNCTIONAL_STATE(NewState));
664 if (NewState != DISABLE)
667 SPIx->CR2 |= (uint16_t)SPI_CR2_SSOE;
672 SPIx->CR2 &= (uint16_t)~((uint16_t)SPI_CR2_SSOE);
693 assert_param(IS_SPI_ALL_PERIPH(SPIx));
694 assert_param(IS_FUNCTIONAL_STATE(NewState));
696 if (NewState != DISABLE)
699 SPIx->CR2 |= SPI_CR2_FRF;
704 SPIx->CR2 &= (uint16_t)~SPI_CR2_FRF;
729 uint16_t tmpreg = 0, tmp = 0;
732 assert_param(IS_I2S_EXT_PERIPH(I2Sxext));
733 assert_param(IS_I2S_MODE(I2S_InitStruct->
I2S_Mode));
734 assert_param(IS_I2S_STANDARD(I2S_InitStruct->
I2S_Standard));
736 assert_param(IS_I2S_CPOL(I2S_InitStruct->
I2S_CPOL));
740 I2Sxext->I2SCFGR &= I2SCFGR_CLEAR_MASK;
741 I2Sxext->I2SPR = 0x0002;
744 tmpreg = I2Sxext->I2SCFGR;
747 if ((I2S_InitStruct->
I2S_Mode == I2S_Mode_MasterTx) || (I2S_InitStruct->
I2S_Mode == I2S_Mode_SlaveTx))
749 tmp = I2S_Mode_SlaveRx;
753 if ((I2S_InitStruct->
I2S_Mode == I2S_Mode_MasterRx) || (I2S_InitStruct->
I2S_Mode == I2S_Mode_SlaveRx))
755 tmp = I2S_Mode_SlaveTx;
761 tmpreg |= (uint16_t)((uint16_t)SPI_I2SCFGR_I2SMOD | (uint16_t)(tmp | \
763 (uint16_t)I2S_InitStruct->
I2S_CPOL))));
766 I2Sxext->I2SCFGR = tmpreg;
804 assert_param(IS_SPI_ALL_PERIPH_EXT(SPIx));
820 assert_param(IS_SPI_ALL_PERIPH_EXT(SPIx));
910 assert_param(IS_SPI_ALL_PERIPH(SPIx));
911 assert_param(IS_FUNCTIONAL_STATE(NewState));
912 if (NewState != DISABLE)
915 SPIx->CR1 |= SPI_CR1_CRCEN;
920 SPIx->CR1 &= (uint16_t)~((uint16_t)SPI_CR1_CRCEN);
932 assert_param(IS_SPI_ALL_PERIPH(SPIx));
935 SPIx->CR1 |= SPI_CR1_CRCNEXT;
951 assert_param(IS_SPI_ALL_PERIPH(SPIx));
952 assert_param(IS_SPI_CRC(SPI_CRC));
953 if (SPI_CRC != SPI_CRC_Rx)
956 crcreg = SPIx->TXCRCR;
961 crcreg = SPIx->RXCRCR;
975 assert_param(IS_SPI_ALL_PERIPH(SPIx));
1009 void SPI_I2S_DMACmd(SPI_TypeDef* SPIx, uint16_t SPI_I2S_DMAReq, FunctionalState NewState)
1012 assert_param(IS_SPI_ALL_PERIPH_EXT(SPIx));
1013 assert_param(IS_FUNCTIONAL_STATE(NewState));
1014 assert_param(IS_SPI_I2S_DMAREQ(SPI_I2S_DMAReq));
1016 if (NewState != DISABLE)
1019 SPIx->CR2 |= SPI_I2S_DMAReq;
1024 SPIx->CR2 &= (uint16_t)~SPI_I2S_DMAReq;
1119 uint16_t itpos = 0, itmask = 0 ;
1122 assert_param(IS_SPI_ALL_PERIPH_EXT(SPIx));
1123 assert_param(IS_FUNCTIONAL_STATE(NewState));
1124 assert_param(IS_SPI_I2S_CONFIG_IT(SPI_I2S_IT));
1127 itpos = SPI_I2S_IT >> 4;
1130 itmask = (uint16_t)1 << (uint16_t)itpos;
1132 if (NewState != DISABLE)
1135 SPIx->CR2 |= itmask;
1140 SPIx->CR2 &= (uint16_t)~itmask;
1163 FlagStatus bitstatus = RESET;
1165 assert_param(IS_SPI_ALL_PERIPH_EXT(SPIx));
1166 assert_param(IS_SPI_I2S_GET_FLAG(SPI_I2S_FLAG));
1169 if ((SPIx->SR & SPI_I2S_FLAG) != (uint16_t)RESET)
1205 assert_param(IS_SPI_ALL_PERIPH_EXT(SPIx));
1206 assert_param(IS_SPI_I2S_CLEAR_FLAG(SPI_I2S_FLAG));
1209 SPIx->SR = (uint16_t)~SPI_I2S_FLAG;
1229 ITStatus bitstatus = RESET;
1230 uint16_t itpos = 0, itmask = 0, enablestatus = 0;
1233 assert_param(IS_SPI_ALL_PERIPH_EXT(SPIx));
1234 assert_param(IS_SPI_I2S_GET_IT(SPI_I2S_IT));
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)
1286 assert_param(IS_SPI_ALL_PERIPH_EXT(SPIx));
1287 assert_param(IS_SPI_I2S_CLEAR_IT(SPI_I2S_IT));
1290 itpos = 0x01 << (SPI_I2S_IT & 0x0F);
1293 SPIx->SR = (uint16_t)~itpos;
This file contains all the functions prototypes for the RCC firmware library.
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_I2S_DMACmd(SPI_TypeDef *SPIx, uint16_t SPI_I2S_DMAReq, FunctionalState NewState)
Enables or disables the SPIx/I2Sx DMA interface.
void SPI_DataSizeConfig(SPI_TypeDef *SPIx, uint16_t SPI_DataSize)
Configures the data size for the selected SPI.
void SPI_TransmitCRC(SPI_TypeDef *SPIx)
Transmit the SPIx CRC value.
This file contains all the functions prototypes for the SPI firmware library.
void SPI_Cmd(SPI_TypeDef *SPIx, FunctionalState NewState)
Enables or disables the specified SPI peripheral.
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_NSSInternalSoftwareConfig(SPI_TypeDef *SPIx, uint16_t SPI_NSSInternalSoft)
Configures internally by software the NSS pin for the selected SPI.
uint16_t SPI_BaudRatePrescaler
I2S Init structure definition.
void SPI_I2S_DeInit(SPI_TypeDef *SPIx)
De-initialize the SPIx peripheral registers to their default reset values.
uint16_t SPI_I2S_ReceiveData(SPI_TypeDef *SPIx)
Returns the most recent received data by the SPIx/I2Sx peripheral.
void SPI_I2S_SendData(SPI_TypeDef *SPIx, uint16_t Data)
Transmits a Data through the SPIx/I2Sx peripheral.
void SPI_I2S_ClearFlag(SPI_TypeDef *SPIx, uint16_t SPI_I2S_FLAG)
Clears the SPIx CRC Error (CRCERR) flag.
SPI Init structure definition.
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.
uint16_t SPI_CRCPolynomial
void SPI_TIModeCmd(SPI_TypeDef *SPIx, FunctionalState NewState)
Enables or disables the SPIx/I2Sx DMA interface.
void SPI_BiDirectionalLineConfig(SPI_TypeDef *SPIx, uint16_t SPI_Direction)
Selects the data transfer direction in bidirectional mode for the specified SPI.
void RCC_APB1PeriphResetCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)
Forces or releases Low Speed APB (APB1) peripheral reset.
ITStatus SPI_I2S_GetITStatus(SPI_TypeDef *SPIx, uint8_t SPI_I2S_IT)
Checks whether the specified SPIx/I2Sx interrupt has occurred or not.
void I2S_StructInit(I2S_InitTypeDef *I2S_InitStruct)
Fills each I2S_InitStruct member with its default value.
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 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 ...
void RCC_APB2PeriphResetCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)
Forces or releases High Speed APB (APB2) peripheral reset.
void SPI_I2S_ClearITPendingBit(SPI_TypeDef *SPIx, uint8_t SPI_I2S_IT)
Clears the SPIx CRC Error (CRCERR) interrupt pending bit.
void SPI_I2S_ITConfig(SPI_TypeDef *SPIx, uint8_t SPI_I2S_IT, FunctionalState NewState)
Enables or disables the specified SPI/I2S interrupts.
void SPI_CalculateCRC(SPI_TypeDef *SPIx, FunctionalState NewState)
Enables or disables the CRC value calculation of the transferred bytes.
void SPI_StructInit(SPI_InitTypeDef *SPI_InitStruct)
Fills each SPI_InitStruct member with its default value.
void SPI_Init(SPI_TypeDef *SPIx, SPI_InitTypeDef *SPI_InitStruct)
Initializes the SPIx peripheral according to the specified parameters in the SPI_InitStruct.