u8 I2C_24C_EEPROM_Write_Page_ByLen (u8 I2c_Address, u16 Mem_Address, char * pBuffer, u16 Len)
{
u8 err;
u8 PagesWritten = 0;
u8 BytesToWrite;
while (Len)
{
if (Len‹MaxPageSizeBytes)
{
BytesToWrite = Len;
Len = 0;
}
else
{
BytesToWrite = MaxPageSizeBytes;
PagesWritten++;
Len-= MaxPageSizeBytes;
}
err=I2c_Start(EEPROM_I2Cx);
if (err) return err;
err=I2c_WriteAddress(EEPROM_I2Cx, I2c_Address);
if (err) return err;
I2c_WriteByte(EEPROM_I2Cx, (0xFF00&Mem_Address)››8);
I2c_WriteByte(EEPROM_I2Cx, 0x00FF&Mem_Address);
while (BytesToWrite--) I2c_WriteByte(EEPROM_I2Cx, * pBuffer++);
I2c_Stop(EEPROM_I2Cx);
delay_ms(I2c_EEPROM_WriteTime_ms);
Mem_Address+= MaxPageSizeBytes;
}
return I2c_Success;
} |