使用STM32红牛开发的GPIO模拟I2C控制八个AT24C02的读写
for(i=0;i<NumByteToRead;i++) {
*pBuffer = I2C_ReceiveData();
++pBuffer;
Ack();
}
NAck();
I2C_GenerateSTOP();
}
void I2C_EE_BufferRead(u8* pBuffer, u16 ReadAddr, u16 NumByteToRead)
{
u16 NumOfPage = 0, NumOfSingle = 0, Addr = 0, count = 0;
Addr = ReadAddr % I2C_PageSize;
count = I2C_PageSize - Addr;
NumOfPage = NumByteToRead / I2C_PageSize;
NumOfSingle = NumByteToRead % I2C_PageSize;
/* If WriteAddr is I2C_PageSize aligned */
if(Addr == 0)
{
/* If NumByteToWrite < I2C_PageSize */
if(NumOfPage == 0)
{ I2C_EE_PageRead(pBuffer, ReadAddr, NumOfSingle);
}
/* If NumByteToWrite > I2C_PageSize */
else
{
while(NumOfPage--)
{
I2C_EE_PageRead(pBuffer, ReadAddr, I2C_PageSize);
ReadAddr += I2C_PageSize;
pBuffer += I2C_PageSize;
}
if(NumOfSingle!=0)
{
I2C_EE_PageRead(pBuffer, ReadAddr, NumOfSingle);
}
}
}
/* If WriteAddr is not I2C_PageSize aligned */