新手上路
- 积分
- 36
- 金钱
- 36
- 注册时间
- 2018-5-10
- 在线时间
- 5 小时
|
2金钱
这是一个事件判断函数 while(!I2C_CheckEvent(I2C1,0x000700082))
ErrorStatus I2C_CheckEvent(I2C_TypeDef* I2Cx, uint32_t I2C_EVENT)
{
uint32_t lastevent = 0;
uint32_t flag1 = 0, flag2 = 0;
ErrorStatus status = ERROR;
/* Check the parameters */
assert_param(IS_I2C_ALL_PERIPH(I2Cx));
assert_param(IS_I2C_EVENT(I2C_EVENT));
/* Read the I2Cx status register */
flag1 = I2Cx->SR1;
flag2 = I2Cx->SR2;
flag2 = flag2 << 16;
/* Get the last event value from I2C status register */
lastevent = (flag1 | flag2) & FLAG_Mask; // 0x0000 0012 = ( 0x0007 0082 ) & 0x1F
/* Check whether the last event contains the I2C_EVENT */
if ((lastevent & I2C_EVENT) == I2C_EVENT) // if ( ( 0x0000 0012 & 0x0007 0082 ) == 0x0007 0082
// 要是这样理解的话,一直while死循环。请问这样理解,错在哪里?
{
/* SUCCESS: last event is equal to I2C_EVENT */
status = SUCCESS;
}
else
{
/* ERROR: last event is different from I2C_EVENT */
status = ERROR;
}
/* Return status */
return status;
}
|
|