大家好: 有没有人用过STM32 I2C作为Master。 1.我发现在一些操作后,比较发送一组数据后,经常地RNE位会自动变为1,导致后续的状态判断不对。贴一段代码: /* Send START condition */ I2C_GenerateSTART(I2C1, ENABLE); /* Test on EV5 and clear it */ while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
/* Send RTC address for read */ I2C_Send7bitAddress(I2C1, COMPANION_ADDRESS, I2C_Direction_Transmitter);
/* Test on EV6 and clear it */ while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); /* Send the RTC internal address 0 */ I2C_SendData(I2C1, 0x00);
/* Test on EV8 and clear it */ while(! I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
/* Send the Read Time Command */ I2C_SendData(I2C1, RTC_READ_TIME);
/* Test on EV8 and clear it */ while(! I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
/* Send STOP condition */ //I2C_GenerateSTOP(I2C1, ENABLE);
/* Send START condition */ I2C_GenerateSTART(I2C1, ENABLE); /* 这里RNE位为1, 检查通不过 **********************/ /* Test on EV5 and clear it */ while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
呵呵,不知道有没有各位有没有碰到过!
2.它的接收控制不太好用,如果在接收处理流程中加中断,就不能正常操作I2C了,好奇怪的设计!
|