/* Clear EV6 by setting again the PE bit */
// I2C_Cmd(I2C1, DISABLE);
/* Test on I2C1 EV6 and clear it */
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
{
if((BatteryTimeout--) == 0) return sEE_TIMEOUT_UserCallback();
}
/*!< Test on EV8_2 and clear it */
BatteryTimeout = BATTERY_FLAG_TIMEOUT;
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTED))
{
if((BatteryTimeout--) == 0) return sEE_TIMEOUT_UserCallback();
}
/*!< Test on EV5 and clear it (cleared by reading SR1 then writing to DR) */
BatteryTimeout = BATTERY_FLAG_TIMEOUT;
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT))
{
if((BatteryTimeout--) == 0) return sEE_TIMEOUT_UserCallback();
}
/* Send Slave address */
I2C_Send7bitAddress(I2Cx, SMBusDefaultHeader, I2C_Direction_Receiver);
/*!< Test on EV6 and clear it */
BatteryTimeout = BATTERY_FLAG_TIMEOUT;
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
{
if((BatteryTimeout--) == 0) return sEE_TIMEOUT_UserCallback();
}
while(NumByteToRead)
{
if(I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED)) //读取数据
{
//调用库函数将数据取出到 pBuffer
*pBuffer = I2C_ReceiveData(I2Cx);
pBuffer++; //指针移位
NumByteToRead--;//字节数减 1
I2C_AcknowledgeConfig(I2Cx, ENABLE);
/*!< Test on EV7 and clear it */
BatteryTimeout = BATTERY_FLAG_TIMEOUT;
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED))
{
if((BatteryTimeout--) == 0) return sEE_TIMEOUT_UserCallback();
}
}
if ((uint16_t)(NumByteToRead) == 1)
{
/* Wait on ADDR flag to be set (ADDR is still not cleared at this level */
// BatteryTimeout = BATTERY_FLAG_TIMEOUT;
// while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_ADDR) == RESET)
// {
// if((BatteryTimeout--) == 0) return sEE_TIMEOUT_UserCallback();
// }
/* Wait for the byte to be received */
while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_RXNE) == RESET)
{
if((BatteryTimeout--) == 0) return sEE_TIMEOUT_UserCallback();
}