在710 I2C的datasheet中有句:“当作为主接受器时,要在最后一次接受数据字节后产生非应答脉冲,必须在读入倒数第二个数据字节之前清楚ACK位。” 所以void EEPROM_Receive(I2C_TypeDef *I2Cx, char *PtrToBuffer,u8 NbOfBytes, u8 InternalAddress)是这样处理的: while(NbOfBytes) { /* Wait until the byte is received */ while (I2C_FlagStatus (I2Cx, DIRECT, I2C_BTF )==RESET);
if(NbOfBytes==2) { /* Disable the ACK generation */ I2C_AcknowledgeConfig (I2Cx, DISABLE); }
if (NbOfBytes==1) { /* Generate STOP condition to close the communication after the next byte reception */ I2C_STOPGenerate (I2Cx, ENABLE); }
*PtrToBuffer=I2C_ByteReceive (I2Cx); PtrToBuffer++; NbOfBytes--; }
因为NbOfBytes为1,所以不能有“读入倒数第二个数据字节之前” 我改为
while(I2C_FlagStatus(I2Cx, DIRECT, I2C_BTF) == RESET); // Wait until the byte is received
I2C_AcknowledgeConfig(I2Cx, DISABLE); // Disable the ACK eneration I2C_STOPGenerate(I2Cx, ENABLE);
*PtrToBuffer = I2C_ByteReceive(I2Cx);
I2C_AcknowledgeConfig(I2Cx, ENABLE); // Enable the ACK generation
这样虽然能够读出正确的数据,但是IIC总线的SDA不能被释放。。。
|