/** * @brief Checks whether the specified I2C interrupt has occurred or not. * @param I2Cx: where x can be 1 or 2 to select the I2C peripheral. * @param I2C_IT: specifies the interrupt source to check. * This parameter can be one of the following values: * @arg I2C_IT_SMBALERT: SMBus Alert flag * @arg I2C_IT_TIMEOUT: Timeout or Tlow error flag * @arg I2C_IT_PECERR: PEC error in reception flag * @arg I2C_IT_OVR: Overrun/Underrun flag (Slave mode) * @arg I2C_IT_AF: Acknowledge failure flag * @arg I2C_IT_ARLO: Arbitration lost flag (Master mode) * @arg I2C_IT_BERR: Bus error flag * @arg I2C_IT_TXE: Data register empty flag (Transmitter) * @arg I2C_IT_RXNE: Data register not empty (Receiver) flag * @arg I2C_IT_STOPF: Stop detection flag (Slave mode) * @arg I2C_IT_ADD10: 10-bit header sent flag (Master mode) * @arg I2C_IT_BTF: Byte transfer finished flag * @arg I2C_IT_ADDR: Address sent flag (Master mode) "ADSL" * Address matched flag (Slave mode)"ENDAD" * @arg I2C_IT_SB: Start bit flag (Master mode) * @retval The new state of I2C_IT (SET or RESET). */ ITStatus I2C_GetITStatus(I2C_TypeDef* I2Cx, uint32_t I2C_IT) { ITStatus bitstatus = RESET; uint32_t enablestatus = 0; /* Check the parameters */ assert_param(IS_I2C_ALL_PERIPH(I2Cx)); assert_param(IS_I2C_GET_IT(I2C_IT)); /* Check if the interrupt source is enabled or not */ enablestatus = (uint32_t)(((I2C_IT & ITEN_Mask) >> 16) & (I2Cx->CR2)) ; /* Get bit[23:0] of the flag */ I2C_IT &= FLAG_Mask; /* Check the status of the specified I2C flag */ if (((I2Cx->SR1 & I2C_IT) != (uint32_t)RESET) && enablestatus) { /* I2C_IT is set */ bitstatus = SET; } else { /* I2C_IT is reset */ bitstatus = RESET; } /* Return the I2C_IT status */ return bitstatus; }
/******************************************************************************* * Function Name : I2C_GetITStatus * Description : Checks whether the specified I2C interrupt has occurred or not. * Input : - I2Cx: where x can be 1 or 2 to select the I2C peripheral. * - I2C_IT: specifies the interrupt source to check. * 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_TXE: Data register empty flag (Transmitter) * - I2C_IT_RXNE: Data register not empty (Receiver) 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 : The new state of I2C_IT (SET or RESET). *******************************************************************************/ ITStatus I2C_GetITStatus(I2C_TypeDef* I2Cx, u32 I2C_IT) { ITStatus bitstatus = RESET; u32 i2cstatus = 0; u32 Flag1 = 0, Flag2 = 0; /* Check the parameters */ assert_param(IS_I2C_GET_IT(I2C_IT)); /* Read the I2Cx status register */ Flag1 = I2Cx->SR1; Flag2 = I2Cx->SR2; Flag2 = (Flag2 & I2C_FLAG_Mask) << 16; /* Get the I2C status value */ i2cstatus = Flag1 | Flag2; /* Get bit[27:0] of the flag */ I2C_IT &= I2C_FLAG_Mask; /* Check the status of the specified I2C flag */ if ((i2cstatus & I2C_IT) != (u32)RESET) { /* I2C_IT is set */ bitstatus = SET; } else { /* I2C_IT is reset */ bitstatus = RESET; } /* Return the I2C_IT status */ return bitstatus; }