/*******************************************************************************
* Function Name  : SPI_ClearFlag
* Description    : Clears the SPIx's pending flags.
* Input          : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
*                  - SPI_FLAG: specifies the flag to clear. 
*                    This parameter can be any combination of the following values:
*                       - SPI_FLAG_OVR: Overrun flag.
*                       - SPI_FLAG_MODF: Mode Fault flag.
*                       - SPI_FLAG_CRCERR: CRC Error flag.
* Output         : None
* Return         : None
*******************************************************************************/
void SPI_ClearFlag(SPI_TypeDef* SPIx, u16 SPI_FLAG)
{
  /* Check the parameters */
  assert(IS_SPI_CLEAR_FLAG(SPI_FLAG));
    
  /* SPI_FLAG_MODF flag clear */
  if(SPI_FLAG == SPI_FLAG_MODF)
  {
    /* Read SR register */
    (void)SPIx->SR;
    /* Write on CR1 register */
    SPIx->CR1 |= CR1_SPE_Set; 
  }
  /* SPI_FLAG_OVR flag clear */
  else if(SPI_FLAG == SPI_FLAG_OVR)  
  {
    /* Read SR register */
    (void)SPIx->SR;
  }
  else /* SPI_FLAG_CRCERR flag clear */
  {
    /* Clear the selected SPI flag */
    SPIx->SR &= (u16)~SPI_FLAG;
  }
}
示例#2
0
/**
  * @brief  Clears the SPIx CRC Error (CRCERR) flag.
  * @param  SPIx: where x can be 1 or 2 to select the SPI peripheral.
  * @param  SPI_I2S_FLAG: specifies the SPI flag to clear. 
  *         This function clears only CRCERR flag.
  * @note   OVR (OverRun error) flag is cleared by software sequence: a read 
  *         operation to SPI_DR register (SPI_I2S_ReceiveData()) followed by  
  *         a read operation to SPI_SR register (SPI_I2S_GetFlagStatus()).
  * @note   MODF (Mode Fault) flag is cleared by software sequence: a read/write 
  *         operation to SPI_SR register (SPI_I2S_GetFlagStatus()) followed by
  *         a write operation to SPI_CR1 register (SPI_Cmd() to enable the SPI).
  * @retval None
  */
void SPI_I2S_ClearFlag(SPI_TypeDef* SPIx, uint16_t SPI_I2S_FLAG)
{
  /* Check the parameters */
  assert_param(IS_SPI_ALL_PERIPH(SPIx));
  assert_param(IS_SPI_CLEAR_FLAG(SPI_I2S_FLAG));

  /* Clear the selected SPI CRC Error (CRCERR) flag */
  SPIx->SR = (uint16_t)~SPI_I2S_FLAG;
}