在线等!哪位大侠用过三星NAND FLASH K9K8G08U0A
[复制链接]
小弟我最近再用NAND FLASH K9K8G08U0A(8Gbit)作为DSP2812的外扩存储器,我是用IO口模拟时序进行读写,按照三星的技术文档现在写了页写(Page _Write)和页读(Page_Read)两个函数,把一页写入数据(如:1,2,3,4,5等,一页共2112*8bit),读出来的全是0xFF,哪位用过的大侠来指点下啊,源程序如下:
//=========Flash 专用头文件 (定义了一些IO口和变量还有函数)================
#include"DSP281x_Device.h" // DSP281x Headerfile Include File
#include"DSP281x_Examples.h" // DSP281x Examples Include File
#define FLASH_IO0 GpioDataRegs.GPADAT.bit.GPIOA0
#define FLASH_IO1 GpioDataRegs.GPADAT.bit.GPIOA1
#define FLASH_IO2 GpioDataRegs.GPADAT.bit.GPIOA2
#define FLASH_IO3 GpioDataRegs.GPADAT.bit.GPIOA3
#define FLASH_IO4 GpioDataRegs.GPADAT.bit.GPIOA4
#define FLASH_IO5 GpioDataRegs.GPADAT.bit.GPIOA5
#define FLASH_IO6 GpioDataRegs.GPADAT.bit.GPIOA6
#define FLASH_IO7 GpioDataRegs.GPADAT.bit.GPIOA7
#define FLASH_RB GpioDataRegs.GPDDAT.bit.GPIOD0
#define FLASH_RE GpioDataRegs.GPDDAT.bit.GPIOD1
#define FLASH_CLE GpioDataRegs.GPADAT.bit.GPIOA11
#define FLASH_ALE GpioDataRegs.GPADAT.bit.GPIOA12
#define FLASH_WE GpioDataRegs.GPADAT.bit.GPIOA13
#define FLASH_WP GpioDataRegs.GPADAT.bit.GPIOA14
#define FLASH_Delay DSP28x_usDelay
#define FLASH_Port FLASH_IO0+(FLASH_IO1<<1)+(FLASH_IO2<<2)+(FLASH_IO3<<3)+(FLASH_IO4<<4)+(FLASH_IO5<<5)+(FLASH_IO6<<6)+(FLASH_IO7<<7)
extern void Page_Write(Uint32 Address,Uchar *Array,Uint16 ArrayLength);
extern void Page_Read(Uint32 Address,Uchar *Array,Uint16 ArrayLength);
extern void AddConver(Uint32 Address);
extern void InputPort(Uchar Command);
extern void WriteCmd(Uchar Command);
extern void WriteData(Uchar Data);
extern Uchar ReadData(void);
extern void WriteAdd(Uint32 Address);
extern Uchar FLASH_ReadStatus(Uchar Command);
注:另有DSP定义口为IO还是外设口,输入还是输出的函数我就没有放上来
//==========下面就是页写和页读函数=====================
//===页写函数====================
void Page_Write(Uint32 Address,Uchar *Array,Uint16 ArrayLength)
{
Uint16 i;
Uchar Statustemp;
FLASH_WP =1;
FLASH_RE = 1;
WriteCmd(0x80);
WriteAdd(Address);
FLASH_CLE = 0;
FLASH_ALE = 0;
FLASH_Delay(2); //FLASH_Delay(1)大约为7ns
for(i=0;i
{
WriteData(*(Array+i));
}
WriteCmd(0x10);
while(FLASH_RB == 0);
FLASH_Delay(2);
Statustemp = FLASH_ReadStatus(0x70);
if((Statustemp & 0x01) == 1) //检验写是否出错,我写的时候这个标志没有置位,说明没有出错
{
ERR = 1;
}
}
void Page_Read(Uint32 Address,Uchar *Array,Uint16 ArrayLength)
{
Uint16 i;
WriteCmd(0x00);
WriteAdd(Address);
WriteCmd(0x30);
while(FLASH_RB == 0);
FLASH_RE = 1;
FLASH_CLE = 0;
FLASH_WE = 1;
FLASH_ALE = 0;
FLASH_Delay(2);
//==========I/O 0- I/O 7设置为输入==================
EALLOW;
GpioMuxRegs.GPADIR.bit.GPIOA0 = 0;
GpioMuxRegs.GPADIR.bit.GPIOA1 = 0;
GpioMuxRegs.GPADIR.bit.GPIOA2 = 0;
GpioMuxRegs.GPADIR.bit.GPIOA3 = 0;
GpioMuxRegs.GPADIR.bit.GPIOA4 = 0;
GpioMuxRegs.GPADIR.bit.GPIOA5 = 0;
GpioMuxRegs.GPADIR.bit.GPIOA6 = 0;
GpioMuxRegs.GPADIR.bit.GPIOA7 = 0;
EDIS;
for(i=0;i
{
*(Array+i) = ReadData();
}
}
//=========写命令函数======================
void WriteCmd(Uchar Command)
{
FLASH_WP =1;
while(FLASH_RB == 0);
FLASH_Delay(3);
FLASH_ALE = 0;
FLASH_CLE = 1;
FLASH_WE = 0;
InputPort(Command);
FLASH_Delay(2);
FLASH_WE = 1;
FLASH_CLE = 0;
}
//==========写数据函数============================
void WriteData(Uchar Data)
{
FLASH_WE = 0;
InputPort(Data);
FLASH_Delay(1);
FLASH_WE = 1;
FLASH_Delay(1);
}
//==========读数据命令=================
Uchar ReadData(void)
{
Uchar Rdata;
//==========I/O 0-I/O 7为输入口===========
FLASH_RE = 0;
FLASH_Delay(2);
Rdata = FLASH_Port; /*读取1B*/
FLASH_RE = 1;
FLASH_Delay(2);
return(Rdata);
}
//=========写地址函数========================
void WriteAdd(Uint32 Address)
{
Uint16 i;
AddConver(Address);
FLASH_CLE = 0;
for(i=0;i<5;i++)
{
while(FLASH_RB == 0);
FLASH_ALE = 1;
FLASH_WE = 0;
switch(i)
{
case 0:
InputPort(CAdd1);
break;
case 1:
InputPort(CAdd2);
break;
case 2:
InputPort(RAdd1);
break;
case 3:
InputPort(RAdd2);
break;
case 4:
InputPort(RAdd3);
break;
}
FLASH_Delay(2);
FLASH_WE = 1;
FLASH_Delay(1);
//=========页写的时序图中在地址写入时ALE一直为高=========
// FLASH_ALE = 0;
// FLASH_Delay(2);
}
}
Uchar FLASH_ReadStatus(Uchar Command)
{
Uchar StatusData;
WriteCmd(Command);
FLASH_Delay(8);
FLASH_RE = 0;
FLASH_Delay(1);
StatusData = FLASH_Port;
FLASH_RE = 1;
FLASH_Delay(2);
return(StatusData);
}
void InputPort(Uchar Command)
{
//==========I/O 0-I/O 7最为输出口===========
EALLOW;
GpioMuxRegs.GPADIR.bit.GPIOA0 = 1;
GpioMuxRegs.GPADIR.bit.GPIOA1 = 1;
GpioMuxRegs.GPADIR.bit.GPIOA2 = 1;
GpioMuxRegs.GPADIR.bit.GPIOA3 = 1;
GpioMuxRegs.GPADIR.bit.GPIOA4 = 1;
GpioMuxRegs.GPADIR.bit.GPIOA5 = 1;
GpioMuxRegs.GPADIR.bit.GPIOA6 = 1;
GpioMuxRegs.GPADIR.bit.GPIOA7 = 1;
EDIS;
//========I/O 0的值=================
if(Command & 0x01)
{
FLASH_IO0 = 1;
}
else
{
FLASH_IO0 = 0;
}
//========I/O 1的值=================
if(Command & 0x02)
{
FLASH_IO1 = 1;
}
else
{
FLASH_IO1 = 0;
}
//========I/O 2的值=================
if(Command & 0x04)
{
FLASH_IO2 = 1;
}
else
{
FLASH_IO2 = 0;
}
//========I/O 3的值=================
if(Command & 0x08)
{
FLASH_IO3 = 1;
}
else
{
FLASH_IO3 = 0;
}
//========I/O 4的值=================
if(Command & 0x10)
{
FLASH_IO4 = 1;
}
else
{
FLASH_IO4 = 0;
}
//========I/O 5的值=================
if(Command & 0x20)
{
FLASH_IO5 = 1;
}
else
{
FLASH_IO5 = 0;
}
//========I/O 6的值=================
if(Command & 0x40)
{
FLASH_IO6 = 1;
}
else
{
FLASH_IO6 = 0;
}
//========I/O 7的值=================
if(Command & 0x80)
{
FLASH_IO7 = 1;
}
else
{
FLASH_IO7 = 0;
}
}
void AddConver(Uint32 Address)
{
CAdd1 = (Uchar)(Address & 0x000000FF);
CAdd2 = (Uchar)((Address & 0x00000F00)>>8);
RAdd1 = (Uchar)((Address & 0x000FF000)>>12);
RAdd2 = (Uchar)((Address & 0x0FF00000)>>20);
RAdd3 = (Uchar)((Address & 0xF0000000)>>28);
}
大侠们帮我看看啊 我都困扰了好几天了 ,不知道是不是有什么问题,用过的帮帮忙啊,谢谢了