STM32F10x Standard Peripherals Library  3.5.0
/opt/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_spi.c
Go to the documentation of this file.
00001 
00022 /* Includes ------------------------------------------------------------------*/
00023 #include "stm32f10x_spi.h"
00024 #include "stm32f10x_rcc.h"
00025 
00048 /* SPI SPE mask */
00049 #define CR1_SPE_Set          ((uint16_t)0x0040)
00050 #define CR1_SPE_Reset        ((uint16_t)0xFFBF)
00051 
00052 /* I2S I2SE mask */
00053 #define I2SCFGR_I2SE_Set     ((uint16_t)0x0400)
00054 #define I2SCFGR_I2SE_Reset   ((uint16_t)0xFBFF)
00055 
00056 /* SPI CRCNext mask */
00057 #define CR1_CRCNext_Set      ((uint16_t)0x1000)
00058 
00059 /* SPI CRCEN mask */
00060 #define CR1_CRCEN_Set        ((uint16_t)0x2000)
00061 #define CR1_CRCEN_Reset      ((uint16_t)0xDFFF)
00062 
00063 /* SPI SSOE mask */
00064 #define CR2_SSOE_Set         ((uint16_t)0x0004)
00065 #define CR2_SSOE_Reset       ((uint16_t)0xFFFB)
00066 
00067 /* SPI registers Masks */
00068 #define CR1_CLEAR_Mask       ((uint16_t)0x3040)
00069 #define I2SCFGR_CLEAR_Mask   ((uint16_t)0xF040)
00070 
00071 /* SPI or I2S mode selection masks */
00072 #define SPI_Mode_Select      ((uint16_t)0xF7FF)
00073 #define I2S_Mode_Select      ((uint16_t)0x0800) 
00074 
00075 /* I2S clock source selection masks */
00076 #define I2S2_CLOCK_SRC       ((uint32_t)(0x00020000))
00077 #define I2S3_CLOCK_SRC       ((uint32_t)(0x00040000))
00078 #define I2S_MUL_MASK         ((uint32_t)(0x0000F000))
00079 #define I2S_DIV_MASK         ((uint32_t)(0x000000F0))
00080 
00119 void SPI_I2S_DeInit(SPI_TypeDef* SPIx)
00120 {
00121   /* Check the parameters */
00122   assert_param(IS_SPI_ALL_PERIPH(SPIx));
00123 
00124   if (SPIx == SPI1)
00125   {
00126     /* Enable SPI1 reset state */
00127     RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, ENABLE);
00128     /* Release SPI1 from reset state */
00129     RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, DISABLE);
00130   }
00131   else if (SPIx == SPI2)
00132   {
00133     /* Enable SPI2 reset state */
00134     RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, ENABLE);
00135     /* Release SPI2 from reset state */
00136     RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, DISABLE);
00137   }
00138   else
00139   {
00140     if (SPIx == SPI3)
00141     {
00142       /* Enable SPI3 reset state */
00143       RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, ENABLE);
00144       /* Release SPI3 from reset state */
00145       RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, DISABLE);
00146     }
00147   }
00148 }
00149 
00158 void SPI_Init(SPI_TypeDef* SPIx, SPI_InitTypeDef* SPI_InitStruct)
00159 {
00160   uint16_t tmpreg = 0;
00161   
00162   /* check the parameters */
00163   assert_param(IS_SPI_ALL_PERIPH(SPIx));   
00164   
00165   /* Check the SPI parameters */
00166   assert_param(IS_SPI_DIRECTION_MODE(SPI_InitStruct->SPI_Direction));
00167   assert_param(IS_SPI_MODE(SPI_InitStruct->SPI_Mode));
00168   assert_param(IS_SPI_DATASIZE(SPI_InitStruct->SPI_DataSize));
00169   assert_param(IS_SPI_CPOL(SPI_InitStruct->SPI_CPOL));
00170   assert_param(IS_SPI_CPHA(SPI_InitStruct->SPI_CPHA));
00171   assert_param(IS_SPI_NSS(SPI_InitStruct->SPI_NSS));
00172   assert_param(IS_SPI_BAUDRATE_PRESCALER(SPI_InitStruct->SPI_BaudRatePrescaler));
00173   assert_param(IS_SPI_FIRST_BIT(SPI_InitStruct->SPI_FirstBit));
00174   assert_param(IS_SPI_CRC_POLYNOMIAL(SPI_InitStruct->SPI_CRCPolynomial));
00175 
00176 /*---------------------------- SPIx CR1 Configuration ------------------------*/
00177   /* Get the SPIx CR1 value */
00178   tmpreg = SPIx->CR1;
00179   /* Clear BIDIMode, BIDIOE, RxONLY, SSM, SSI, LSBFirst, BR, MSTR, CPOL and CPHA bits */
00180   tmpreg &= CR1_CLEAR_Mask;
00181   /* Configure SPIx: direction, NSS management, first transmitted bit, BaudRate prescaler
00182      master/salve mode, CPOL and CPHA */
00183   /* Set BIDImode, BIDIOE and RxONLY bits according to SPI_Direction value */
00184   /* Set SSM, SSI and MSTR bits according to SPI_Mode and SPI_NSS values */
00185   /* Set LSBFirst bit according to SPI_FirstBit value */
00186   /* Set BR bits according to SPI_BaudRatePrescaler value */
00187   /* Set CPOL bit according to SPI_CPOL value */
00188   /* Set CPHA bit according to SPI_CPHA value */
00189   tmpreg |= (uint16_t)((uint32_t)SPI_InitStruct->SPI_Direction | SPI_InitStruct->SPI_Mode |
00190                   SPI_InitStruct->SPI_DataSize | SPI_InitStruct->SPI_CPOL |  
00191                   SPI_InitStruct->SPI_CPHA | SPI_InitStruct->SPI_NSS |  
00192                   SPI_InitStruct->SPI_BaudRatePrescaler | SPI_InitStruct->SPI_FirstBit);
00193   /* Write to SPIx CR1 */
00194   SPIx->CR1 = tmpreg;
00195   
00196   /* Activate the SPI mode (Reset I2SMOD bit in I2SCFGR register) */
00197   SPIx->I2SCFGR &= SPI_Mode_Select;             
00198 
00199 /*---------------------------- SPIx CRCPOLY Configuration --------------------*/
00200   /* Write to SPIx CRCPOLY */
00201   SPIx->CRCPR = SPI_InitStruct->SPI_CRCPolynomial;
00202 }
00203 
00219 void I2S_Init(SPI_TypeDef* SPIx, I2S_InitTypeDef* I2S_InitStruct)
00220 {
00221   uint16_t tmpreg = 0, i2sdiv = 2, i2sodd = 0, packetlength = 1;
00222   uint32_t tmp = 0;
00223   RCC_ClocksTypeDef RCC_Clocks;
00224   uint32_t sourceclock = 0;
00225   
00226   /* Check the I2S parameters */
00227   assert_param(IS_SPI_23_PERIPH(SPIx));
00228   assert_param(IS_I2S_MODE(I2S_InitStruct->I2S_Mode));
00229   assert_param(IS_I2S_STANDARD(I2S_InitStruct->I2S_Standard));
00230   assert_param(IS_I2S_DATA_FORMAT(I2S_InitStruct->I2S_DataFormat));
00231   assert_param(IS_I2S_MCLK_OUTPUT(I2S_InitStruct->I2S_MCLKOutput));
00232   assert_param(IS_I2S_AUDIO_FREQ(I2S_InitStruct->I2S_AudioFreq));
00233   assert_param(IS_I2S_CPOL(I2S_InitStruct->I2S_CPOL));  
00234 
00235 /*----------------------- SPIx I2SCFGR & I2SPR Configuration -----------------*/
00236   /* Clear I2SMOD, I2SE, I2SCFG, PCMSYNC, I2SSTD, CKPOL, DATLEN and CHLEN bits */
00237   SPIx->I2SCFGR &= I2SCFGR_CLEAR_Mask; 
00238   SPIx->I2SPR = 0x0002;
00239   
00240   /* Get the I2SCFGR register value */
00241   tmpreg = SPIx->I2SCFGR;
00242   
00243   /* If the default value has to be written, reinitialize i2sdiv and i2sodd*/
00244   if(I2S_InitStruct->I2S_AudioFreq == I2S_AudioFreq_Default)
00245   {
00246     i2sodd = (uint16_t)0;
00247     i2sdiv = (uint16_t)2;   
00248   }
00249   /* If the requested audio frequency is not the default, compute the prescaler */
00250   else
00251   {
00252     /* Check the frame length (For the Prescaler computing) */
00253     if(I2S_InitStruct->I2S_DataFormat == I2S_DataFormat_16b)
00254     {
00255       /* Packet length is 16 bits */
00256       packetlength = 1;
00257     }
00258     else
00259     {
00260       /* Packet length is 32 bits */
00261       packetlength = 2;
00262     }
00263 
00264     /* Get the I2S clock source mask depending on the peripheral number */
00265     if(((uint32_t)SPIx) == SPI2_BASE)
00266     {
00267       /* The mask is relative to I2S2 */
00268       tmp = I2S2_CLOCK_SRC;
00269     }
00270     else 
00271     {
00272       /* The mask is relative to I2S3 */      
00273       tmp = I2S3_CLOCK_SRC;
00274     }
00275 
00276     /* Check the I2S clock source configuration depending on the Device:
00277        Only Connectivity line devices have the PLL3 VCO clock */
00278 #ifdef STM32F10X_CL
00279     if((RCC->CFGR2 & tmp) != 0)
00280     {
00281       /* Get the configuration bits of RCC PLL3 multiplier */
00282       tmp = (uint32_t)((RCC->CFGR2 & I2S_MUL_MASK) >> 12);
00283 
00284       /* Get the value of the PLL3 multiplier */      
00285       if((tmp > 5) && (tmp < 15))
00286       {
00287         /* Multiplier is between 8 and 14 (value 15 is forbidden) */
00288         tmp += 2;
00289       }
00290       else
00291       {
00292         if (tmp == 15)
00293         {
00294           /* Multiplier is 20 */
00295           tmp = 20;
00296         }
00297       }      
00298       /* Get the PREDIV2 value */
00299       sourceclock = (uint32_t)(((RCC->CFGR2 & I2S_DIV_MASK) >> 4) + 1);
00300       
00301       /* Calculate the Source Clock frequency based on PLL3 and PREDIV2 values */
00302       sourceclock = (uint32_t) ((HSE_Value / sourceclock) * tmp * 2); 
00303     }
00304     else
00305     {
00306       /* I2S Clock source is System clock: Get System Clock frequency */
00307       RCC_GetClocksFreq(&RCC_Clocks);      
00308       
00309       /* Get the source clock value: based on System Clock value */
00310       sourceclock = RCC_Clocks.SYSCLK_Frequency;
00311     }        
00312 #else /* STM32F10X_HD */
00313     /* I2S Clock source is System clock: Get System Clock frequency */
00314     RCC_GetClocksFreq(&RCC_Clocks);      
00315       
00316     /* Get the source clock value: based on System Clock value */
00317     sourceclock = RCC_Clocks.SYSCLK_Frequency;    
00318 #endif /* STM32F10X_CL */    
00319 
00320     /* Compute the Real divider depending on the MCLK output state with a floating point */
00321     if(I2S_InitStruct->I2S_MCLKOutput == I2S_MCLKOutput_Enable)
00322     {
00323       /* MCLK output is enabled */
00324       tmp = (uint16_t)(((((sourceclock / 256) * 10) / I2S_InitStruct->I2S_AudioFreq)) + 5);
00325     }
00326     else
00327     {
00328       /* MCLK output is disabled */
00329       tmp = (uint16_t)(((((sourceclock / (32 * packetlength)) *10 ) / I2S_InitStruct->I2S_AudioFreq)) + 5);
00330     }
00331     
00332     /* Remove the floating point */
00333     tmp = tmp / 10;  
00334       
00335     /* Check the parity of the divider */
00336     i2sodd = (uint16_t)(tmp & (uint16_t)0x0001);
00337    
00338     /* Compute the i2sdiv prescaler */
00339     i2sdiv = (uint16_t)((tmp - i2sodd) / 2);
00340    
00341     /* Get the Mask for the Odd bit (SPI_I2SPR[8]) register */
00342     i2sodd = (uint16_t) (i2sodd << 8);
00343   }
00344   
00345   /* Test if the divider is 1 or 0 or greater than 0xFF */
00346   if ((i2sdiv < 2) || (i2sdiv > 0xFF))
00347   {
00348     /* Set the default values */
00349     i2sdiv = 2;
00350     i2sodd = 0;
00351   }
00352 
00353   /* Write to SPIx I2SPR register the computed value */
00354   SPIx->I2SPR = (uint16_t)(i2sdiv | (uint16_t)(i2sodd | (uint16_t)I2S_InitStruct->I2S_MCLKOutput));  
00355  
00356   /* Configure the I2S with the SPI_InitStruct values */
00357   tmpreg |= (uint16_t)(I2S_Mode_Select | (uint16_t)(I2S_InitStruct->I2S_Mode | \
00358                   (uint16_t)(I2S_InitStruct->I2S_Standard | (uint16_t)(I2S_InitStruct->I2S_DataFormat | \
00359                   (uint16_t)I2S_InitStruct->I2S_CPOL))));
00360  
00361   /* Write to SPIx I2SCFGR */  
00362   SPIx->I2SCFGR = tmpreg;   
00363 }
00364 
00370 void SPI_StructInit(SPI_InitTypeDef* SPI_InitStruct)
00371 {
00372 /*--------------- Reset SPI init structure parameters values -----------------*/
00373   /* Initialize the SPI_Direction member */
00374   SPI_InitStruct->SPI_Direction = SPI_Direction_2Lines_FullDuplex;
00375   /* initialize the SPI_Mode member */
00376   SPI_InitStruct->SPI_Mode = SPI_Mode_Slave;
00377   /* initialize the SPI_DataSize member */
00378   SPI_InitStruct->SPI_DataSize = SPI_DataSize_8b;
00379   /* Initialize the SPI_CPOL member */
00380   SPI_InitStruct->SPI_CPOL = SPI_CPOL_Low;
00381   /* Initialize the SPI_CPHA member */
00382   SPI_InitStruct->SPI_CPHA = SPI_CPHA_1Edge;
00383   /* Initialize the SPI_NSS member */
00384   SPI_InitStruct->SPI_NSS = SPI_NSS_Hard;
00385   /* Initialize the SPI_BaudRatePrescaler member */
00386   SPI_InitStruct->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
00387   /* Initialize the SPI_FirstBit member */
00388   SPI_InitStruct->SPI_FirstBit = SPI_FirstBit_MSB;
00389   /* Initialize the SPI_CRCPolynomial member */
00390   SPI_InitStruct->SPI_CRCPolynomial = 7;
00391 }
00392 
00398 void I2S_StructInit(I2S_InitTypeDef* I2S_InitStruct)
00399 {
00400 /*--------------- Reset I2S init structure parameters values -----------------*/
00401   /* Initialize the I2S_Mode member */
00402   I2S_InitStruct->I2S_Mode = I2S_Mode_SlaveTx;
00403   
00404   /* Initialize the I2S_Standard member */
00405   I2S_InitStruct->I2S_Standard = I2S_Standard_Phillips;
00406   
00407   /* Initialize the I2S_DataFormat member */
00408   I2S_InitStruct->I2S_DataFormat = I2S_DataFormat_16b;
00409   
00410   /* Initialize the I2S_MCLKOutput member */
00411   I2S_InitStruct->I2S_MCLKOutput = I2S_MCLKOutput_Disable;
00412   
00413   /* Initialize the I2S_AudioFreq member */
00414   I2S_InitStruct->I2S_AudioFreq = I2S_AudioFreq_Default;
00415   
00416   /* Initialize the I2S_CPOL member */
00417   I2S_InitStruct->I2S_CPOL = I2S_CPOL_Low;
00418 }
00419 
00427 void SPI_Cmd(SPI_TypeDef* SPIx, FunctionalState NewState)
00428 {
00429   /* Check the parameters */
00430   assert_param(IS_SPI_ALL_PERIPH(SPIx));
00431   assert_param(IS_FUNCTIONAL_STATE(NewState));
00432   if (NewState != DISABLE)
00433   {
00434     /* Enable the selected SPI peripheral */
00435     SPIx->CR1 |= CR1_SPE_Set;
00436   }
00437   else
00438   {
00439     /* Disable the selected SPI peripheral */
00440     SPIx->CR1 &= CR1_SPE_Reset;
00441   }
00442 }
00443 
00451 void I2S_Cmd(SPI_TypeDef* SPIx, FunctionalState NewState)
00452 {
00453   /* Check the parameters */
00454   assert_param(IS_SPI_23_PERIPH(SPIx));
00455   assert_param(IS_FUNCTIONAL_STATE(NewState));
00456   if (NewState != DISABLE)
00457   {
00458     /* Enable the selected SPI peripheral (in I2S mode) */
00459     SPIx->I2SCFGR |= I2SCFGR_I2SE_Set;
00460   }
00461   else
00462   {
00463     /* Disable the selected SPI peripheral (in I2S mode) */
00464     SPIx->I2SCFGR &= I2SCFGR_I2SE_Reset;
00465   }
00466 }
00467 
00482 void SPI_I2S_ITConfig(SPI_TypeDef* SPIx, uint8_t SPI_I2S_IT, FunctionalState NewState)
00483 {
00484   uint16_t itpos = 0, itmask = 0 ;
00485   /* Check the parameters */
00486   assert_param(IS_SPI_ALL_PERIPH(SPIx));
00487   assert_param(IS_FUNCTIONAL_STATE(NewState));
00488   assert_param(IS_SPI_I2S_CONFIG_IT(SPI_I2S_IT));
00489 
00490   /* Get the SPI/I2S IT index */
00491   itpos = SPI_I2S_IT >> 4;
00492 
00493   /* Set the IT mask */
00494   itmask = (uint16_t)1 << (uint16_t)itpos;
00495 
00496   if (NewState != DISABLE)
00497   {
00498     /* Enable the selected SPI/I2S interrupt */
00499     SPIx->CR2 |= itmask;
00500   }
00501   else
00502   {
00503     /* Disable the selected SPI/I2S interrupt */
00504     SPIx->CR2 &= (uint16_t)~itmask;
00505   }
00506 }
00507 
00521 void SPI_I2S_DMACmd(SPI_TypeDef* SPIx, uint16_t SPI_I2S_DMAReq, FunctionalState NewState)
00522 {
00523   /* Check the parameters */
00524   assert_param(IS_SPI_ALL_PERIPH(SPIx));
00525   assert_param(IS_FUNCTIONAL_STATE(NewState));
00526   assert_param(IS_SPI_I2S_DMAREQ(SPI_I2S_DMAReq));
00527   if (NewState != DISABLE)
00528   {
00529     /* Enable the selected SPI/I2S DMA requests */
00530     SPIx->CR2 |= SPI_I2S_DMAReq;
00531   }
00532   else
00533   {
00534     /* Disable the selected SPI/I2S DMA requests */
00535     SPIx->CR2 &= (uint16_t)~SPI_I2S_DMAReq;
00536   }
00537 }
00538 
00547 void SPI_I2S_SendData(SPI_TypeDef* SPIx, uint16_t Data)
00548 {
00549   /* Check the parameters */
00550   assert_param(IS_SPI_ALL_PERIPH(SPIx));
00551   
00552   /* Write in the DR register the data to be sent */
00553   SPIx->DR = Data;
00554 }
00555 
00563 uint16_t SPI_I2S_ReceiveData(SPI_TypeDef* SPIx)
00564 {
00565   /* Check the parameters */
00566   assert_param(IS_SPI_ALL_PERIPH(SPIx));
00567   
00568   /* Return the data in the DR register */
00569   return SPIx->DR;
00570 }
00571 
00581 void SPI_NSSInternalSoftwareConfig(SPI_TypeDef* SPIx, uint16_t SPI_NSSInternalSoft)
00582 {
00583   /* Check the parameters */
00584   assert_param(IS_SPI_ALL_PERIPH(SPIx));
00585   assert_param(IS_SPI_NSS_INTERNAL(SPI_NSSInternalSoft));
00586   if (SPI_NSSInternalSoft != SPI_NSSInternalSoft_Reset)
00587   {
00588     /* Set NSS pin internally by software */
00589     SPIx->CR1 |= SPI_NSSInternalSoft_Set;
00590   }
00591   else
00592   {
00593     /* Reset NSS pin internally by software */
00594     SPIx->CR1 &= SPI_NSSInternalSoft_Reset;
00595   }
00596 }
00597 
00605 void SPI_SSOutputCmd(SPI_TypeDef* SPIx, FunctionalState NewState)
00606 {
00607   /* Check the parameters */
00608   assert_param(IS_SPI_ALL_PERIPH(SPIx));
00609   assert_param(IS_FUNCTIONAL_STATE(NewState));
00610   if (NewState != DISABLE)
00611   {
00612     /* Enable the selected SPI SS output */
00613     SPIx->CR2 |= CR2_SSOE_Set;
00614   }
00615   else
00616   {
00617     /* Disable the selected SPI SS output */
00618     SPIx->CR2 &= CR2_SSOE_Reset;
00619   }
00620 }
00621 
00631 void SPI_DataSizeConfig(SPI_TypeDef* SPIx, uint16_t SPI_DataSize)
00632 {
00633   /* Check the parameters */
00634   assert_param(IS_SPI_ALL_PERIPH(SPIx));
00635   assert_param(IS_SPI_DATASIZE(SPI_DataSize));
00636   /* Clear DFF bit */
00637   SPIx->CR1 &= (uint16_t)~SPI_DataSize_16b;
00638   /* Set new DFF bit value */
00639   SPIx->CR1 |= SPI_DataSize;
00640 }
00641 
00647 void SPI_TransmitCRC(SPI_TypeDef* SPIx)
00648 {
00649   /* Check the parameters */
00650   assert_param(IS_SPI_ALL_PERIPH(SPIx));
00651   
00652   /* Enable the selected SPI CRC transmission */
00653   SPIx->CR1 |= CR1_CRCNext_Set;
00654 }
00655 
00663 void SPI_CalculateCRC(SPI_TypeDef* SPIx, FunctionalState NewState)
00664 {
00665   /* Check the parameters */
00666   assert_param(IS_SPI_ALL_PERIPH(SPIx));
00667   assert_param(IS_FUNCTIONAL_STATE(NewState));
00668   if (NewState != DISABLE)
00669   {
00670     /* Enable the selected SPI CRC calculation */
00671     SPIx->CR1 |= CR1_CRCEN_Set;
00672   }
00673   else
00674   {
00675     /* Disable the selected SPI CRC calculation */
00676     SPIx->CR1 &= CR1_CRCEN_Reset;
00677   }
00678 }
00679 
00689 uint16_t SPI_GetCRC(SPI_TypeDef* SPIx, uint8_t SPI_CRC)
00690 {
00691   uint16_t crcreg = 0;
00692   /* Check the parameters */
00693   assert_param(IS_SPI_ALL_PERIPH(SPIx));
00694   assert_param(IS_SPI_CRC(SPI_CRC));
00695   if (SPI_CRC != SPI_CRC_Rx)
00696   {
00697     /* Get the Tx CRC register */
00698     crcreg = SPIx->TXCRCR;
00699   }
00700   else
00701   {
00702     /* Get the Rx CRC register */
00703     crcreg = SPIx->RXCRCR;
00704   }
00705   /* Return the selected CRC register */
00706   return crcreg;
00707 }
00708 
00714 uint16_t SPI_GetCRCPolynomial(SPI_TypeDef* SPIx)
00715 {
00716   /* Check the parameters */
00717   assert_param(IS_SPI_ALL_PERIPH(SPIx));
00718   
00719   /* Return the CRC polynomial register */
00720   return SPIx->CRCPR;
00721 }
00722 
00732 void SPI_BiDirectionalLineConfig(SPI_TypeDef* SPIx, uint16_t SPI_Direction)
00733 {
00734   /* Check the parameters */
00735   assert_param(IS_SPI_ALL_PERIPH(SPIx));
00736   assert_param(IS_SPI_DIRECTION(SPI_Direction));
00737   if (SPI_Direction == SPI_Direction_Tx)
00738   {
00739     /* Set the Tx only mode */
00740     SPIx->CR1 |= SPI_Direction_Tx;
00741   }
00742   else
00743   {
00744     /* Set the Rx only mode */
00745     SPIx->CR1 &= SPI_Direction_Rx;
00746   }
00747 }
00748 
00766 FlagStatus SPI_I2S_GetFlagStatus(SPI_TypeDef* SPIx, uint16_t SPI_I2S_FLAG)
00767 {
00768   FlagStatus bitstatus = RESET;
00769   /* Check the parameters */
00770   assert_param(IS_SPI_ALL_PERIPH(SPIx));
00771   assert_param(IS_SPI_I2S_GET_FLAG(SPI_I2S_FLAG));
00772   /* Check the status of the specified SPI/I2S flag */
00773   if ((SPIx->SR & SPI_I2S_FLAG) != (uint16_t)RESET)
00774   {
00775     /* SPI_I2S_FLAG is set */
00776     bitstatus = SET;
00777   }
00778   else
00779   {
00780     /* SPI_I2S_FLAG is reset */
00781     bitstatus = RESET;
00782   }
00783   /* Return the SPI_I2S_FLAG status */
00784   return  bitstatus;
00785 }
00786 
00804 void SPI_I2S_ClearFlag(SPI_TypeDef* SPIx, uint16_t SPI_I2S_FLAG)
00805 {
00806   /* Check the parameters */
00807   assert_param(IS_SPI_ALL_PERIPH(SPIx));
00808   assert_param(IS_SPI_I2S_CLEAR_FLAG(SPI_I2S_FLAG));
00809     
00810     /* Clear the selected SPI CRC Error (CRCERR) flag */
00811     SPIx->SR = (uint16_t)~SPI_I2S_FLAG;
00812 }
00813 
00829 ITStatus SPI_I2S_GetITStatus(SPI_TypeDef* SPIx, uint8_t SPI_I2S_IT)
00830 {
00831   ITStatus bitstatus = RESET;
00832   uint16_t itpos = 0, itmask = 0, enablestatus = 0;
00833 
00834   /* Check the parameters */
00835   assert_param(IS_SPI_ALL_PERIPH(SPIx));
00836   assert_param(IS_SPI_I2S_GET_IT(SPI_I2S_IT));
00837 
00838   /* Get the SPI/I2S IT index */
00839   itpos = 0x01 << (SPI_I2S_IT & 0x0F);
00840 
00841   /* Get the SPI/I2S IT mask */
00842   itmask = SPI_I2S_IT >> 4;
00843 
00844   /* Set the IT mask */
00845   itmask = 0x01 << itmask;
00846 
00847   /* Get the SPI_I2S_IT enable bit status */
00848   enablestatus = (SPIx->CR2 & itmask) ;
00849 
00850   /* Check the status of the specified SPI/I2S interrupt */
00851   if (((SPIx->SR & itpos) != (uint16_t)RESET) && enablestatus)
00852   {
00853     /* SPI_I2S_IT is set */
00854     bitstatus = SET;
00855   }
00856   else
00857   {
00858     /* SPI_I2S_IT is reset */
00859     bitstatus = RESET;
00860   }
00861   /* Return the SPI_I2S_IT status */
00862   return bitstatus;
00863 }
00864 
00883 void SPI_I2S_ClearITPendingBit(SPI_TypeDef* SPIx, uint8_t SPI_I2S_IT)
00884 {
00885   uint16_t itpos = 0;
00886   /* Check the parameters */
00887   assert_param(IS_SPI_ALL_PERIPH(SPIx));
00888   assert_param(IS_SPI_I2S_CLEAR_IT(SPI_I2S_IT));
00889 
00890   /* Get the SPI IT index */
00891   itpos = 0x01 << (SPI_I2S_IT & 0x0F);
00892 
00893   /* Clear the selected SPI CRC Error (CRCERR) interrupt pending bit */
00894   SPIx->SR = (uint16_t)~itpos;
00895 }
00908 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/