/*******************************************************************************
* Function Name  : SPI_I2S_ClearFlag
* Description    : Clears the SPIx/I2Sx pending flags.
* Input          : - SPIx: where x can be :
*                         - 1, 2 or 3 in SPI mode 
*                         - 2 or 3 in I2S mode
*                  - SPI_I2S_FLAG: specifies the SPI/I2S flag to clear. 
*                    This parameter can be one of the following values:
*                       - SPI_I2S_FLAG_OVR: Overrun flag 
*                       - SPI_FLAG_MODF: Mode Fault flag.
*                       - SPI_FLAG_CRCERR: CRC Error flag.
*                       - I2S_FLAG_UDR: Underrun Error flag.
*                    Note: Before clearing OVR flag, it is mandatory to read 
*                          SPI_I2S_DR register, so that the last data is not lost.
* Output         : None
* Return         : None
*******************************************************************************/
void SPI_I2S_ClearFlag(SPI_TypeDef* SPIx, u16 SPI_I2S_FLAG)
{
  /* Check the parameters */
  assert_param(IS_SPI_ALL_PERIPH(SPIx));
  assert_param(IS_SPI_I2S_CLEAR_FLAG(SPI_I2S_FLAG));
    
  /* SPI_FLAG_MODF flag clear */
  if(SPI_I2S_FLAG == SPI_FLAG_MODF)
  {
    /* Read SR register */
    (void)SPIx->SR;
    
    /* Write on CR1 register */
    SPIx->CR1 |= CR1_SPE_Set; 
  }
  /* SPI_I2S_FLAG_OVR flag or I2S_FLAG_UDR flag clear */
  else if ((SPI_I2S_FLAG == SPI_I2S_FLAG_OVR) || (SPI_I2S_FLAG == I2S_FLAG_UDR))  
  {
    /* Read SR register  (Before clearing OVR flag, it is mandatory to read 
       SPI_I2S_DR register)*/
    (void)SPIx->SR;
  }
  else /* SPI_FLAG_CRCERR flag clear */
  {
    /* Clear the selected SPI flag */
    SPIx->SR = (u16)~SPI_I2S_FLAG;
  }
}
Example #2
0
/*******************************************************************************
* 函数名称: SPI_I2S_ClearFlag
* 功能描述: 清除SPIx CRC错误(CRCERR) 标志.
* 输入参数: (1)SPIx: x可以是 :
*                         - 1, 2 或 3 在 SPI 模式 
*           (2)SPI_I2S_FLAG: 指定清除的SPI标志. 
*                    这个函数只能清除CRCERR标志.                                           
*                  注意:
*                       - OVR (过速错误)中断挂起位可以被软件按顺序清除: 一个读  
*                         SPI_DR寄存器操作 (SPI_I2S_ReceiveData()) 跟着一个读  
*                         SPI_SR寄存器操作 (SPI_I2S_GetITStatus()).
*                       - UDR (空栈读错误) 中断挂起位可以被一个读SPI_SR寄存器操
*                         作清除(SPI_I2S_GetITStatus())。
*                       - MODF (模式错误) 中断挂起位被软件按顺序清除:一个读/写 
*                         SPI_SR寄存器操作(SPI_I2S_GetITStatus())跟着一个写SPI_CR1 
*                         寄存器操作 (SPI_Cmd() 使能 SPI).    
* 输出参数: 无
* 返回参数: 无
*******************************************************************************/
void SPI_I2S_ClearFlag(SPI_TypeDef* SPIx, u16 SPI_I2S_FLAG)
{
  /* Check the parameters [检查参数]*/
  assert_param(IS_SPI_ALL_PERIPH(SPIx));
  assert_param(IS_SPI_I2S_CLEAR_FLAG(SPI_I2S_FLAG));
    
    /* Clear the selected SPI CRC Error (CRCERR) flag [清除选择的SPI CRC错误(CRCERR)标志]*/
    SPIx->SR = (u16)~SPI_I2S_FLAG;
}
Example #3
0
/**
  * @brief  Clears the SPIx CRC Error (CRCERR) flag.
  * @param SPIx: where x can be :
  *   1, 2 or 3 in SPI mode 
  * @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()).
  *   - UDR (UnderRun error) flag is cleared by a read operation to 
  *     SPI_SR register (SPI_I2S_GetFlagStatus()).
  *   - 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_I2S_CLEAR_FLAG(SPI_I2S_FLAG));
    
    /* Clear the selected SPI CRC Error (CRCERR) flag */
    SPIx->SR = (uint16_t)~SPI_I2S_FLAG;
}