各位大虾,我用STM32F103VBT和24C08用I2C通讯,利用库(V2.03)的函数进行,先写数据,再读,在读的过程中,EV6处SR1变为0x0044,而下面的判断需要是0x0040,程序在这死循环,跳不出来,请各位帮看看,已经搞两天,开始好使过一阵子,后面就一直这样。请帮忙,谢谢。
下面是读这块的程序:
void I2C_EE_BufferRead(u8* pBuffer, u8 ReadAddr, u16 NumByteToRead)
{
I2C_EE_WaitEepromStandbyState();
/* Send START condition */
I2C_GenerateSTART(I2C2, ENABLE);
/* Test on EV5 and clear it */
while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT));
/* Send EEPROM address for write */
I2C_Send7bitAddress(I2C2, EEPROM_ADDRESS, I2C_Direction_Transmitter);
/* Test on EV6 and clear it */
while(!I2C_CheckEvent(I2C2,
I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
/* Clear EV6 by setting again the PE bit */
I2C_Cmd(I2C2, ENABLE);
/* Send the EEPROM's internal address to write to */
I2C_SendData(I2C2, ReadAddr);
/* Test on EV8 and clear it */
while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
/* Send STRAT condition a second time */
I2C_GenerateSTART(I2C2, ENABLE);
/* Test on EV5 and clear it */
while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT));
/* Send EEPROM address for read */
I2C_Send7bitAddress(I2C2, EEPROM_ADDRESS, I2C_Direction_Receiver);
/* Test on EV6 and clear it */
while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
/* While there is data to be read */
//////////问题在这跳不出去了,看寄存器的值SR1是0044,SR2是0003,而后面的比较值I2C_EVENT_MASTER_BYTE_RECEIVED是00030040。相差SR的bit2:BTF位
while(NumByteToRead) //
{
if(NumByteToRead == 1)
{
/* Disable Acknowledgement */
I2C_AcknowledgeConfig(I2C2, DISABLE);
/* Send STOP Condition */
I2C_GenerateSTOP(I2C2, ENABLE);
}
/* Test on EV7 and clear it */
if(I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_RECEIVED))
{
/* Read a byte from the EEPROM */
*pBuffer = I2C_ReceiveData(I2C2);
/* Point to the next location where the byte read will be saved */
pBuffer++;
/* Decrement the read bytes counter */
NumByteToRead--;
}
}
/* Enable Acknowledgement to be ready for another reception */
I2C_AcknowledgeConfig(I2C2, ENABLE);
}