小学生
最后登录1970-1-1
在线时间 小时
注册时间2014-3-13
|
火哥,我发现了个问题,代码中164行开始:
else
{
/* If NumByteToWrite < I2C_PageSize */
if(NumOfPage== 0)
{
I2C_EE_PageWrite(pBuffer, WriteAddr, NumOfSingle);
I2C_EE_WaitEepromStandbyState();
}
else
{
NumByteToWrite -= count;
这里已经判断Addr不为0,但此时如果NumOfSingle>count,则会出现页首(NumOfSingle-count)个数据被覆盖的问题。因此我建议此程序能否作以下修改:
void I2C_EE_BufferWrite( u8 *Buffer, u8 WriteAddr, u16 NumByteToWrite )
{
u8 NumOfPage = 0, NumOfSingle = 0, Addr = 0, count = 0;
Addr = WriteAddr % EEPROM_PAGESIZE;
if( Addr != 0 ) //测试地址是否为页开始地址
{
count = EEPROM_PAGESIZE - Addr;
NumByteToWrite -= count;
I2C_EEPROM_PageWrite( Buffer, WriteAddr, count );
I2C_EEPROM_WaitStandbyState();
WriteAddr += count;
Buffer += count;
}
NumOfPage = NumByteToWrite / EEPROM_PAGESIZE; //计算剩余页数
NumOfSingle = NumByteToWrite % EEPROM_PAGESIZE; //计算不足一页的字节数
if( NumOfPage > 0 ) //测试页数是否大于0
{
while( NumOfPage-- )
{
I2C_EEPROM_PageWrite( Buffer, WriteAddr, EEPROM_PAGESIZE ); //写一页数据
I2C_EEPROM_WaitStandbyState();
WriteAddr += EEPROM_PAGESIZE;
Buffer += EEPROM_PAGESIZE;
}
}
if( NumOfSingle != 0 )
{
I2C_EEPROM_PageWrite( Buffer, WriteAddr, NumOfSingle ); //写剩余不足一页的数据
I2C_EEPROM_WaitStandbyState();
}
}
|
|