对24c32块写的时候出现异常,当我在写函数位置设置断点,可以写正常,当把断点取消就无法写入,
/*******************************************************************************
*功能描述 : 写eeprom页
*输入参数 : uint16_t EepromAddr -- eeprom内部地址
* uint8_t *Eepromdata -- eeprom写入buf
* uint8_t WriteNumber -- eeprom写入字节数
*说明 :WriteNumber根据不同芯片最大限值不同
*******************************************************************************/
void EepromWritePage(uint16_t EepromAddr,uint8_t *Eepromdata,uint8_t WriteNumber)
{
IIC_Start();
IIC_WriteByte(EEPROM_ID);
IIC_ReceiveAck();
IIC_WriteByte((EepromAddr>>8)&0x0f);
IIC_ReceiveAck();
IIC_WriteByte(EepromAddr&0xff);
IIC_ReceiveAck();
while(WriteNumber--)
{
IIC_WriteByte(*Eepromdata++);
IIC_ReceiveAck();
}
IIC_Stop();
}
/*******************************************************************************
*功能描述 : 写Eeprom中数据入buf
*输入参数 : uint16_t EepromAddr -- eeprom内部地址
* uint8_t *EepromBuf -- eeprom写入buf
* uint8_t WriteNumber -- eeprom写入字节数
*说明 : 此函数突破eeprom页的限制可随意写入其中一段存储空间
*******************************************************************************/
void EepromWriteBuf(uint16_t EepromAddr,uint8_t *EepromBuf,uint8_t WriteNumber)
{
uint8_t Num_page = 0,Num_tmp = 0,Addr_Count = 0;
uint16_t Addr_tmp = 0;
Addr_tmp = EepromAddr%PAGE_SIZE;
Addr_Count = PAGE_SIZE-Addr_tmp;
Num_page = WriteNumber/PAGE_SIZE;
Num_tmp = WriteNumber%PAGE_SIZE;
if(Addr_tmp == 0)
{
if(Num_page == 0)
{
EepromWritePage(EepromAddr,EepromBuf,WriteNumber);
}
else
{
while(Num_page--)
{
EepromWritePage(EepromAddr,EepromBuf,PAGE_SIZE);
EepromAddr += PAGE_SIZE;
EepromBuf += PAGE_SIZE;
}
if(Num_tmp)
EepromWritePage(EepromAddr,EepromBuf,Num_tmp);
}
}
else
{
if(Num_page == 0)
{
if(WriteNumber>Addr_Count)
{
EepromWritePage(EepromAddr,EepromBuf,Addr_Count);
EepromBuf += Addr_Count;
EepromAddr += Addr_Count;
EepromWritePage(EepromAddr,EepromBuf,WriteNumber-Addr_Count);
}
else
{
EepromWritePage(EepromAddr,EepromBuf,Num_tmp);
}
}
else
{
WriteNumber -= Addr_Count;
Num_page = WriteNumber/PAGE_SIZE;
Num_tmp = WriteNumber%PAGE_SIZE;
if(Addr_Count)
{
EepromWritePage(EepromAddr,EepromBuf,Addr_Count);
EepromBuf += Addr_Count;
EepromAddr += Addr_Count;
}
while(Num_page--)
{
EepromWritePage(EepromAddr,EepromBuf,PAGE_SIZE);
EepromAddr += PAGE_SIZE;
EepromBuf += PAGE_SIZE;
}
if(Num_tmp)
EepromWritePage(EepromAddr,EepromBuf,Num_tmp);
}
}
}
|