注册会员
- 积分
- 45
- 威望
- 31
- 贡献
- 14
- 兑换币
- 13
- 注册时间
- 2013-3-15
- 在线时间
- 0 小时
- 毕业学校
- 东南大学
|
3#
楼主 |
发表于 2013-3-15 20:59:29
|
只看该作者
void EFlash_MemoryWrite(VUINT16 PA,VUINT16 BFA,VUINT8 *pHeader,VUINT16 len)
{
VUINT8 stateRegister;
//将长度为len,首地址为pHeader的数写入以BFA为首地址的缓冲区中
EFlash_BufferWrite(BFA,pHeader,len);
//等待 AT45DB321D 的ready
stateRegister = EFlash_StatusRegisterRead();
while(!(stateRegister & 0x80))//空闲
{
RS232_SendChar(0x1F);
//Cpu_Delay100US(1);
stateRegister = EFlash_StatusRegisterRead();
}
SPI_CS_PutVal(0);//使能片选
//执行命令--带自擦除的缓存内容写主存
SPI_HostWriteByte(0x83);//缓冲1的命令
//页地址
SPI_HostWriteByte((VUINT8)(PA>>7));
SPI_HostWriteByte((VUINT8)(PA<<1));
SPI_HostWriteByte(0x00);
SPI_CS_PutVal(1);//片选无效
Cpu_Delay100US(10);
}
/*-------------------------------------------------------------------------
功 能: 读主存
-------------------------------------------------------------------------*/
void EFlash_MemoryRead(VUINT16 PA,VUINT16 BFA,VUINT8 *pHeader,VUINT16 len)
{
VUINT16 i=0,j=0;
word *Rcv=0;
VUINT8 stateRegister;
stateRegister = EFlash_StatusRegisterRead();//读状态寄存器
while(!(stateRegister & 0x80))//空闲
{
//RS232_SendChar(0x11);
stateRegister = EFlash_StatusRegisterRead();
}
SPI_CS_PutVal(0);
SPI_HostWriteByte(0xD2);
SPI_HostWriteByte((VUINT8)(PA>>7));
SPI_HostWriteByte((VUINT8)(((PA&0x00FF)<<1)|(BFA>>8)));
SPI_HostWriteByte((VUINT8)BFA);
//发送4字节任意码主要是为了给芯片初始化读操作时间的
//在此之后,再变化时钟就可以读取数据了
for(i=0;i<4;i++)
{
SPI_HostWriteByte(0x00); //4字节任意码
}
//读取指定长度数据
for(i=0;i<len;i++)
{
pHeader[i] = SPI_HostReadByte();
}
//SPI_RecvBlock(pHeader,len,Rcv);
SPI_CS_PutVal(1);
}
/*-------------------------------------------------------------------------
功 能: 页擦除
-------------------------------------------------------------------------*/
void EFlash_PageErase(VUINT32 padr)
{
VUINT16 PA;
VUINT8 stateRegister;
PA=padr/512;
stateRegister = EFlash_StatusRegisterRead();//读状态寄存器
while(!(stateRegister & 0x80))//空闲
{
//RS232_SendChar(0x12);
stateRegister = EFlash_StatusRegisterRead();
}
SPI_CS_PutVal(0);
SPI_HostWriteByte(0x81);
SPI_HostWriteByte((VUINT8)(PA>>7));
SPI_HostWriteByte((VUINT8)(PA<<1));
SPI_HostWriteByte(0x00);
SPI_CS_PutVal(1);
} |
|