I2C的问题,很多人都遇到了,这并不奇怪
奇就奇在,,,,开发板商或ST不去做更正
明知有问题,还把程序开发出来给别人用
算了,只是调了两天I2C,把闷气说一说
写第一次OK,再写一次就死掉了
死在 /* Test on EV5 and clear it */ while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
查看I2C_CheckEvent 原型: ErrorStatus I2C_CheckEvent(I2C_TypeDef* I2Cx, u32 I2C_EVENT) { u32 lastevent = 0; u32 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;
/* 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; }
/* Return status */ return status; }
主要在这里: /* 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; ====================================
查看 I2C_EVENT_MASTER_MODE_SELECT 宏定义 /* EV5 */ #define I2C_EVENT_MASTER_MODE_SELECT ((u32)0x00030001) /* BUSY, MSL and SB flag */
当第一次读写I2C时 (flag1 | flag2) & FLAG_Mask == 0x00030001 当第二次读写I2C时 (flag1 | flag2) & FLAG_Mask == 0x00030041 != I2C_EVENT_MASTER_MODE_SELECT
那么就死在这里了
查看 I2C_CR1寄存器 第 6位是 ENGC 查看说明,,这是广播使能位
这位如何会置位,为何初始是0,我没去拷究了
留给ST去解释吧
|