Exemplo n.º 1
0
/**
  * @brief  Clears the I2Cx’s interrupt pending bits.
  * @param  I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  * @param  I2C_IT: specifies the interrupt pending bit to clear.
  *   This parameter can be any combination of the following values:
  *     @arg I2C_IT_SMBALERT: SMBus Alert interrupt
  *     @arg I2C_IT_TIMEOUT: Timeout or Tlow error interrupt
  *     @arg I2C_IT_PECERR: PEC error in reception  interrupt
  *     @arg I2C_IT_OVR: Overrun/Underrun interrupt (Slave mode)
  *     @arg I2C_IT_AF: Acknowledge failure interrupt
  *     @arg I2C_IT_ARLO: Arbitration lost interrupt (Master mode)
  *     @arg I2C_IT_BERR: Bus error interrupt
  *
  * @note
  *   - STOPF (STOP detection) is cleared by software sequence: a read operation
  *     to I2C_SR1 register (I2C_GetITStatus()) followed by a write operation to
  *     I2C_CR1 register (I2C_Cmd() to re-enable the I2C peripheral).
  *   - ADD10 (10-bit header sent) is cleared by software sequence: a read
  *     operation to I2C_SR1 (I2C_GetITStatus()) followed by writing the second
  *     byte of the address in I2C_DR register.
  *   - BTF (Byte Transfer Finished) is cleared by software sequence: a read
  *     operation to I2C_SR1 register (I2C_GetITStatus()) followed by a
  *     read/write to I2C_DR register (I2C_SendData()).
  *   - ADDR (Address sent) is cleared by software sequence: a read operation to
  *     I2C_SR1 register (I2C_GetITStatus()) followed by a read operation to
  *     I2C_SR2 register ((void)(I2Cx->SR2)).
  *   - SB (Start Bit) is cleared by software sequence: a read operation to
  *     I2C_SR1 register (I2C_GetITStatus()) followed by a write operation to
  *     I2C_DR register (I2C_SendData()).
  * @retval None
  */
void I2C_ClearITPendingBit(I2C_TypeDef* I2Cx, uint32_t I2C_IT) {
    uint32_t flagpos = 0;
    /* Check the parameters */
    assert_param(IS_I2C_ALL_PERIPH(I2Cx));
    assert_param(IS_I2C_CLEAR_IT(I2C_IT));
    /* Get the I2C flag position */
    flagpos = I2C_IT & FLAG_Mask;
    /* Clear the selected I2C flag */
    I2Cx->SR1 = (uint16_t)~flagpos;
}
Exemplo n.º 2
0
/*******************************************************************************
* Function Name  : I2C_ClearITPendingBit
* Description    : Clears the I2Cx’s interrupt pending bits.
* Input          : - I2Cx: where x can be 1 or 2 to select the I2C peripheral.
*                  - I2C_IT: specifies the interrupt pending bit to clear. 
*                    This parameter can be one of the following values:
*                       - I2C_IT_SMBALERT: SMBus Alert flag
*                       - I2C_IT_TIMEOUT: Timeout or Tlow error flag
*                       - I2C_IT_PECERR: PEC error in reception flag
*                       - I2C_IT_OVR: Overrun/Underrun flag (Slave mode)
*                       - I2C_IT_AF: Acknowledge failure flag
*                       - I2C_IT_ARLO: Arbitration lost flag (Master mode)
*                       - I2C_IT_BERR: Bus error flag
*                       - I2C_IT_STOPF: Stop detection flag (Slave mode)
*                       - I2C_IT_ADD10: 10-bit header sent flag (Master mode)
*                       - I2C_IT_BTF: Byte transfer finished flag
*                       - I2C_IT_ADDR: Address sent flag (Master mode) “ADSL”
*                                        Address matched flag (Slave mode)”ENDAD”
*                       - I2C_IT_SB: Start bit flag (Master mode)
* Output         : None
* Return         : None
*******************************************************************************/
void I2C_ClearITPendingBit(I2C_TypeDef* I2Cx, u32 I2C_IT)
{
  u32 flagpos = 0;
  u32 flagindex = 0;

  /* Check the parameters */
  assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  assert_param(IS_I2C_CLEAR_IT(I2C_IT));

  /* Get the I2C flag position */
  flagpos = I2C_IT & FLAG_Mask;

  /* Get the I2C flag index */
  flagindex = I2C_IT >> 28;

  /* Clear the flag by writing 0 */
  if (flagindex == 1)
  {
    /* Clear the selected I2C flag */
    I2Cx->SR1 = (u16)~flagpos;
  }
  /* Flags that need a read of the SR1 register to be cleared */
  else if (flagindex == 2)
  {
    /* Read the SR1 register */
    (void)I2Cx->SR1;
  }
  /* Flags that need a read of SR1 and a write on CR1 registers to be cleared */
  else if (flagindex == 6)
  {
    /* Read the SR1 register */
    (void)I2Cx->SR1;

    /* Write on the CR1 register */
    I2Cx->CR1 |= CR1_PE_Set;
  }
  /* Flags that need a read of SR1 and SR2 registers to be cleared */
  else /*flagindex == 0xA*/
  {
    /* Read the SR1 register */
    (void)I2Cx->SR1;

    /* Read the SR2 register */
    (void)I2Cx->SR2;
  }
}