/* Get the last event value from I2C status register */ LastEvent = (Flag1 | Flag2) & I2C_FLAG_Mask;
/* Check whether the last event is equal to I2C_EVENT */ if (LastEvent == I2C_EVENT ) { /* SUCCESS: last event is equal to I2C_EVENT */ status = SUCCESS; } else { /* ERROR: last event is different from I2C_EVENT */ status = ERROR; }
我用STM32读铁电,仿照官方读M24C04的,稍有改动。 写没有问题,随机读取,第一遍OK,之后读写都不行了。。。调试器发现死在EV5的while()里。和楼主的情况相似,不过一直没搞清具体原因。 库函数里如下定义 /* EV5 */ #define I2C_EVENT_MASTER_MODE_SELECT ((u32)0x00030001) /* BUSY, MSL and SB flag */ 但是参考手册里写了这一句: EV5: SB=1, cleared by reading SR1 register followed by writing DR register with Address. 是不是说只要写地址前读了SR1,就自动清了?