本帖最后由 yzzly 于 2016-7-21 18:25 编辑
找到原因了:
读FLASH存储器M25P40的函数由:
void InitEventRecordBuf(void)
{
Uint32 Cnt,RecordByteNum,RecordPageNum;
M25p40PageRead((Uint32 *)&EventRecord[0],EventRecordSectorNum,EventRecordStartPage,sizeof(EventRecordType)/sizeof(Uint32),4);
if(EventRecord[0].EventType > MaxSaveRecordNum)
{
EventRecord[0].EventType=0;
M25p40PageProgram((Uint32 *)&EventRecord[0],EventRecordSectorNum,EventRecordStartPage,sizeof(EventRecordType)/sizeof(Uint32),4);
}
else
{
RecordByteNum=(EventRecord[0].EventType+1)*sizeof(EventRecordType);
RecordPageNum=RecordByteNum/256;
if(RecordByteNum > RecordPageNum * 256)RecordPageNum++;
for(Cnt=0;Cnt<RecordPageNum;Cnt++)
{
M25p40PageRead((Uint32 *)&EventRecord[Cnt*(256/sizeof(EventRecordType))],EventRecordSectorNum,Cnt+EventRecordStartPage,256/sizeof(Uint32),4);
}
}
}
改成了:
void InitEventRecordBuf(void)
{
Uint32 Cnt,RecordByteNum,RecordPageNum;
Uint08 *P1;
M25p40PageRead((Uint32 *)&EventRecord[0],EventRecordSectorNum,EventRecordStartPage,sizeof(EventRecordType)/sizeof(Uint32),4);
if(EventRecord[0].EventType > MaxSaveRecordNum)
{
EventRecord[0].EventType=0;
M25p40PageProgram((Uint32 *)&EventRecord[0],EventRecordSectorNum,EventRecordStartPage,sizeof(EventRecordType)/sizeof(Uint32),4);
}
else
{
RecordByteNum=(EventRecord[0].EventType+1)*sizeof(EventRecordType);
if(RecordByteNum % 256 ==0)RecordPageNum = RecordByteNum / 256;
else RecordPageNum = RecordByteNum / 256 + 1;
P1=(Uint08 *)&EventRecord[0];
for(Cnt=0;Cnt<RecordPageNum;Cnt++)
{
M25p40PageRead((Uint32 *)(P1+Cnt*256),
EventRecordSectorNum,EventRecordStartPage+Cnt,256/sizeof(Uint32),4);
}
}
}就影响101协议的正常接收通信,感觉是与P1指针有关,但不知道为什么,即使else内语句不执行也一样。
之所以改动,是因为上面的函数有问题,改动后的函数操作结果完全正确,但是.......
|