mc9s12xdp512的EEPROM
飞思卡尔 mc9s12xdp512的EEPROM读写,有写过的贴下代码。。。谢了! xdp512的手册有详细的读写流程图,另外可以Codewarrior自带的PE生成代码参考下xdp512的EEPROM可编程为每8字节或每4字节一个扇区,每次写入时要确保该扇区已被擦除,如果是批量写入数据的话,要注意跨扇区的处理,最好是以4字节对齐写入。 0x13_F000 到 0x13_FFFF 这下划线什么意思?
初始化部分:
ECLKDIV = 0x28; //EEPROM CLK 200K
ECNFG = 0x00; //关命令缓冲区空中断,关命令完成中断
EPROT = 0x88; // 关写保护
ESTAT = 0x00; //标志位清零
//写EEPROM
void EEPROMWrite(longAddress,short WData)
{
if(ECLKDIV_EDIVLD == 1)
{
if(ESTAT_CBEIF == 1)
{
if((ESTAT_PVIOL == 0) && (ESTAT_ACCERR == 0))
{
EADDRHI = (Address >> 8) & 0xff;
EADDRLO = Address & 0xff;
EDATAHI = (WData >> 8) & 0xff;
EDATALO = WData & 0xff;
ECMD = 0x20;
ESTAT = 0x80;
while(ESTAT_CBEIF == 0);
while(ESTAT_CCIF == 0);
}
else
{
ESTAT = 0x30;
}
}
else
ECLKDIV = 0x28;
}
}
//擦除
void EEPROMErase(long Address,short EData)
{
if(ECLKDIV_EDIVLD == 1)
{
if(ESTAT_CBEIF == 1)
{
if((ESTAT_PVIOL == 0) && (ESTAT_ACCERR == 0))
{
EADDRHI = (Address >> 8) & 0xff;
EADDRLO = Address & 0xff;
EDATAHI = (EData >> 8) & 0xff;
EDATALO = EData & 0xff;
ECMD = 0x05;
ESTAT = 0x80;
while(ESTAT_CCIF == 0);
while(ESTAT_BLANK == 0);
}
else
{
ESTAT = 0x30;
}
}
else
ECLKDIV = 0x28;
}
}
这样貌似不行。。。有什么问题吗? 高手路过,回答下。。。逻辑地址,页地址,全局地址;
http://cache.amobbs.com/bbs_upload782111/files_47/ourdev_695157PY4HT4.jpg
EEPROM地址 (原文件名:未命名.jpg)
http://cache.amobbs.com/bbs_upload782111/files_47/ourdev_695158L7851P.jpg
MMC,逻辑地址与全局地址 (原文件名:未命名1.jpg) EEprom应该写到什么地址?怎么配置?谢了。 如果你的数据少的话,可以存到0xC00至0x1000这个区间,如果想利用全部4K的EEPROM,就需要通过EPAGE寄存器来将另外的另外的3K空间映射到0x800至0xBFF这个区间。
http://cache.amobbs.com/bbs_upload782111/files_47/ourdev_695601XTQMAO.JPG
(原文件名:xdp512.JPG) 0xC00至0x1000 ,貌似我试过,仿真时MEMERY窗口能看到写进去的值;但断电貌似就丢失了。。。。
硬件都被拿出去调试了,等硬件回来。。。我再试试了。。。。先谢了。
dreampet 原野 留个联系方式吧,呵呵。。我的QQ 549848360 学习一下! unsigned char write(unsigned long addr, unsigned long data)
{
ESTAT_PVIOL = 1;
ESTAT_ACCERR = 1; //clear error flags
if(( ESTAT_PVIOL == 1) || (ESTAT_ACCERR == 1))
{
ESTAT_PVIOL = 1;
ESTAT_ACCERR = 1; //clear error flags
return(0);
}
while(!ESTAT_CBEIF); //if there are still some commands in the buffer, wait
*(unsigned short *far)addr = 0xFF;
ECMD = EE_CMD_SECTORERASE;
ESTAT |= 0x80; //clear the interrupt flag
if((ESTAT_PVIOL == 1) || (ESTAT_ACCERR == 1))//if there are erros
{
ESTAT_PVIOL = 1;
ESTAT_ACCERR = 1; //clear error flags
return(0);
}
while(!ESTAT_CBEIF); //if there are still some commands in the buffer, wait
while(!ESTAT_CCIF);
if( (ESTAT_PVIOL == 1) || (ESTAT_ACCERR == 1))
{
ESTAT_PVIOL=1;
ESTAT_ACCERR=1; //clear error flags
return(0);
}
while(!ESTAT_CBEIF){}; //if there are still some commands in the buffer, wait
*(unsigned short *far)addr = ((unsigned short *)&data);
//write the data into the address
ECMD = EE_CMD_WORDWRITE;
ESTAT |= 0x80; //clear the interrupt flag.
if(ESTAT_PVIOL == 1 || ESTAT_ACCERR == 1) //there are errors.
{
ESTAT_PVIOL=1;
ESTAT_ACCERR=1; //clear the error flags.
return(0);
}
while(!ESTAT_CCIF);
if( (ESTAT_PVIOL == 1) || (ESTAT_ACCERR == 1))
{
ESTAT_PVIOL=1;
ESTAT_ACCERR=1; //clear error flags
return(0);
}
while(!ESTAT_CBEIF){}; //if there are still some commands in the buffer, wait
*(unsigned short *far)(addr+2) = ((unsigned short *)&data); //write the data into the address
ECMD = EE_CMD_WORDWRITE;
ESTAT |= 0x80; //clear the interrupt flag.
if(ESTAT_PVIOL == 1 || ESTAT_ACCERR == 1) //there are errors.
{
ESTAT_PVIOL=1;
ESTAT_ACCERR=1; //clear the error flags.
return(0);
}
while(!ESTAT_CCIF);
return 1;
}
地址从0x13f000开始 unsigned char write(unsigned long addr, unsigned long data)
{
ESTAT_PVIOL = 1;
ESTAT_ACCERR = 1; //clear error flags
if(( ESTAT_PVIOL == 1) || (ESTAT_ACCERR == 1))
{
ESTAT_PVIOL = 1;
ESTAT_ACCERR = 1; //clear error flags
return(0);
}
while(!ESTAT_CBEIF); //if there are still some commands in the buffer, wait
*(unsigned short *far)addr = 0xFF;
ECMD = EE_CMD_SECTORERASE;
ESTAT |= 0x80; //clear the interrupt flag
if((ESTAT_PVIOL == 1) || (ESTAT_ACCERR == 1))//if there are erros
{
ESTAT_PVIOL = 1;
ESTAT_ACCERR = 1; //clear error flags
return(0);
}
while(!ESTAT_CBEIF); //if there are still some commands in the buffer, wait
while(!ESTAT_CCIF);
if( (ESTAT_PVIOL == 1) || (ESTAT_ACCERR == 1))
{
ESTAT_PVIOL=1;
ESTAT_ACCERR=1; //clear error flags
return(0);
}
while(!ESTAT_CBEIF){}; //if there are still some commands in the buffer, wait
*(unsigned short *far)addr = ((unsigned short *)&data);
//write the data into the address
ECMD = EE_CMD_WORDWRITE;
ESTAT |= 0x80; //clear the interrupt flag.
if(ESTAT_PVIOL == 1 || ESTAT_ACCERR == 1) //there are errors.
{
ESTAT_PVIOL=1;
ESTAT_ACCERR=1; //clear the error flags.
return(0);
}
while(!ESTAT_CCIF);
if( (ESTAT_PVIOL == 1) || (ESTAT_ACCERR == 1))
{
ESTAT_PVIOL=1;
ESTAT_ACCERR=1; //clear error flags
return(0);
}
while(!ESTAT_CBEIF){}; //if there are still some commands in the buffer, wait
*(unsigned short *far)(addr+2) = ((unsigned short *)&data); //write the data into the address
ECMD = EE_CMD_WORDWRITE;
ESTAT |= 0x80; //clear the interrupt flag.
if(ESTAT_PVIOL == 1 || ESTAT_ACCERR == 1) //there are errors.
{
ESTAT_PVIOL=1;
ESTAT_ACCERR=1; //clear the error flags.
return(0);
}
while(!ESTAT_CCIF);
return 1;
}
地址从0x13f000开始 unsigned char write(unsigned long addr, unsigned long data)
{
ESTAT_PVIOL = 1;
ESTAT_ACCERR = 1; //clear error flags
if(( ESTAT_PVIOL == 1) || (ESTAT_ACCERR == 1))
{
ESTAT_PVIOL = 1;
ESTAT_ACCERR = 1; //clear error flags
return(0);
}
while(!ESTAT_CBEIF); //if there are still some commands in the buffer, wait
*(unsigned short *far)addr = 0xFF;
ECMD = EE_CMD_SECTORERASE;
ESTAT |= 0x80; //clear the interrupt flag
if((ESTAT_PVIOL == 1) || (ESTAT_ACCERR == 1))//if there are erros
{
ESTAT_PVIOL = 1;
ESTAT_ACCERR = 1; //clear error flags
return(0);
}
while(!ESTAT_CBEIF); //if there are still some commands in the buffer, wait
while(!ESTAT_CCIF);
if( (ESTAT_PVIOL == 1) || (ESTAT_ACCERR == 1))
{
ESTAT_PVIOL=1;
ESTAT_ACCERR=1; //clear error flags
return(0);
}
while(!ESTAT_CBEIF){}; //if there are still some commands in the buffer, wait
*(unsigned short *far)addr = ((unsigned short *)&data);
//write the data into the address
ECMD = EE_CMD_WORDWRITE;
ESTAT |= 0x80; //clear the interrupt flag.
if(ESTAT_PVIOL == 1 || ESTAT_ACCERR == 1) //there are errors.
{
ESTAT_PVIOL=1;
ESTAT_ACCERR=1; //clear the error flags.
return(0);
}
while(!ESTAT_CCIF);
if( (ESTAT_PVIOL == 1) || (ESTAT_ACCERR == 1))
{
ESTAT_PVIOL=1;
ESTAT_ACCERR=1; //clear error flags
return(0);
}
while(!ESTAT_CBEIF){}; //if there are still some commands in the buffer, wait
*(unsigned short *far)(addr+2) = ((unsigned short *)&data); //write the data into the address
ECMD = EE_CMD_WORDWRITE;
ESTAT |= 0x80; //clear the interrupt flag.
if(ESTAT_PVIOL == 1 || ESTAT_ACCERR == 1) //there are errors.
{
ESTAT_PVIOL=1;
ESTAT_ACCERR=1; //clear the error flags.
return(0);
}
while(!ESTAT_CCIF);
return 1;
}
地址从0x13f000开始
页:
[1]