examples/stm32l1xx_ldiscovery/StdPeripheralDriver/src/stm32l1xx_spi.c
/**
  * @brief  Initializes the SPIx peripheral according to the specified 
  *         parameters in the SPI_InitStruct.
  * @param  SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
  * @param  SPI_InitStruct: pointer to a SPI_InitTypeDef structure that
  *         contains the configuration information for the specified SPI peripheral.
  * @retval None
  */
@brief  Initializes the SPIx peripheral according to the specified
parameters in the SPI_InitStruct.
@param  SPIx: where x can be 1, 2 or 3 to select the SPI peripheral.
@param  SPI_InitStruct: pointer to a SPI_InitTypeDef structure that
contains the configuration information for the specified SPI peripheral.
@retval None
@brief Initializes the SPIx peripheral according to the specified parameters in the SPI_InitStruct . @param SPIx : where x can be 1 2 or 3 to select the SPI peripheral . @param SPI_InitStruct : pointer to a SPI_InitTypeDef structure that contains the configuration information for the specified SPI peripheral . @retval None
void SPI_Init(SPI_TypeDef* SPIx, SPI_InitTypeDef* SPI_InitStruct)
{
  uint16_t tmpreg = 0;
  assert_param(IS_SPI_ALL_PERIPH(SPIx));
  assert_param(IS_SPI_DIRECTION_MODE(SPI_InitStruct->SPI_Direction));
  assert_param(IS_SPI_MODE(SPI_InitStruct->SPI_Mode));
  assert_param(IS_SPI_DATASIZE(SPI_InitStruct->SPI_DataSize));
  assert_param(IS_SPI_CPOL(SPI_InitStruct->SPI_CPOL));
  assert_param(IS_SPI_CPHA(SPI_InitStruct->SPI_CPHA));
  assert_param(IS_SPI_NSS(SPI_InitStruct->SPI_NSS));
  assert_param(IS_SPI_BAUDRATE_PRESCALER(SPI_InitStruct->SPI_BaudRatePrescaler));
  assert_param(IS_SPI_FIRST_BIT(SPI_InitStruct->SPI_FirstBit));
  assert_param(IS_SPI_CRC_POLYNOMIAL(SPI_InitStruct->SPI_CRCPolynomial));
  tmpreg = SPIx->CR1;
  tmpreg &= CR1_CLEAR_MASK;
  tmpreg |= (uint16_t)((uint32_t)SPI_InitStruct->SPI_Direction | SPI_InitStruct->SPI_Mode |
                  SPI_InitStruct->SPI_DataSize | SPI_InitStruct->SPI_CPOL |  
                  SPI_InitStruct->SPI_CPHA | SPI_InitStruct->SPI_NSS |  
                  SPI_InitStruct->SPI_BaudRatePrescaler | SPI_InitStruct->SPI_FirstBit);
  SPIx->CR1 = tmpreg;
  SPIx->I2SCFGR &= (uint16_t)~((uint16_t)SPI_I2SCFGR_I2SMOD);
  SPIx->CRCPR = SPI_InitStruct->SPI_CRCPolynomial;
}
void SPI_Init ( SPI_TypeDef * SPIx , SPI_InitTypeDef * SPI_InitStruct ) { uint16_t tmpreg = 0 ; assert_param ( IS_SPI_ALL_PERIPH ( SPIx ) ) ; assert_param ( IS_SPI_DIRECTION_MODE ( SPI_InitStruct -> SPI_Direction ) ) ; assert_param ( IS_SPI_MODE ( SPI_InitStruct -> SPI_Mode ) ) ; assert_param ( IS_SPI_DATASIZE ( SPI_InitStruct -> SPI_DataSize ) ) ; assert_param ( IS_SPI_CPOL ( SPI_InitStruct -> SPI_CPOL ) ) ; assert_param ( IS_SPI_CPHA ( SPI_InitStruct -> SPI_CPHA ) ) ; assert_param ( IS_SPI_NSS ( SPI_InitStruct -> SPI_NSS ) ) ; assert_param ( IS_SPI_BAUDRATE_PRESCALER ( SPI_InitStruct -> SPI_BaudRatePrescaler ) ) ; assert_param ( IS_SPI_FIRST_BIT ( SPI_InitStruct -> SPI_FirstBit ) ) ; assert_param ( IS_SPI_CRC_POLYNOMIAL ( SPI_InitStruct -> SPI_CRCPolynomial ) ) ; tmpreg = SPIx -> CR1 ; tmpreg &= CR1_CLEAR_MASK ; tmpreg |= ( uint16_t ) ( ( uint32_t ) SPI_InitStruct -> SPI_Direction | SPI_InitStruct -> SPI_Mode | SPI_InitStruct -> SPI_DataSize | SPI_InitStruct -> SPI_CPOL | SPI_InitStruct -> SPI_CPHA | SPI_InitStruct -> SPI_NSS | SPI_InitStruct -> SPI_BaudRatePrescaler | SPI_InitStruct -> SPI_FirstBit ) ; SPIx -> CR1 = tmpreg ; SPIx -> I2SCFGR &= ( uint16_t ) ~ ( ( uint16_t ) SPI_I2SCFGR_I2SMOD ) ; SPIx -> CRCPR = SPI_InitStruct -> SPI_CRCPolynomial ; }
@brief  Initializes the SPIx peripheral according to the specified
         parameters in the SPI_InitStruct.
@brief Initializes the SPIx peripheral according to the specified parameters in the SPI_InitStruct .
/* check the parameters */ /* Check the SPI parameters */ /*---------------------------- SPIx CR1 Configuration ------------------------*/ /* Get the SPIx CR1 value */ /* Clear BIDIMode, BIDIOE, RxONLY, SSM, SSI, LSBFirst, BR, MSTR, CPOL and CPHA bits */ /* Configure SPIx: direction, NSS management, first transmitted bit, BaudRate prescaler
     master/salve mode, CPOL and CPHA */ /* Set BIDImode, BIDIOE and RxONLY bits according to SPI_Direction value */ /* Set SSM, SSI and MSTR bits according to SPI_Mode and SPI_NSS values */ /* Set LSBFirst bit according to SPI_FirstBit value */ /* Set BR bits according to SPI_BaudRatePrescaler value */ /* Set CPOL bit according to SPI_CPOL value */ /* Set CPHA bit according to SPI_CPHA value */ /* Write to SPIx CR1 */ /* Activate the SPI mode (Reset I2SMOD bit in I2SCFGR register) */ /*---------------------------- SPIx CRCPOLY Configuration --------------------*/ /* Write to SPIx CRCPOLY */