K9F2808,程序采用模拟时序的方法,外挂在arm上,参考了坛子的程序
目前读ID遇到这样的情况,掉电后读ID,第一次读到FFFF,第二次才能读到,每次都这样。
读写页面就一点都不正常,读出来全部是FF,在线求助。。。。。。
//写命令 void NFWrCmd(uint8 cmd) { OS_ENTER_CRITICAL(); NF_DPORT_OUT; NF_ALE_CLR; NF_nCS_CLR; NF_CLE_SET; NF_nWE_CLR; FIO3SET |= (uint32)cmd; NF_nWE_SET; NF_CLE_CLR; NF_ALE_SET; OS_EXIT_CRITICAL(); }
//写地址 void NFWrAddr(uint8 addr) { OS_ENTER_CRITICAL(); NF_DPORT_OUT; NF_nWE_SET; NF_nCS_CLR; NF_CLE_CLR; NF_ALE_SET; NF_nWE_CLR; FIO3SET |= (uint32)addr; NF_nWE_SET; NF_BUSY_END; // wait busy end
NF_ALE_CLR; OS_EXIT_CRITICAL(); }
//写数据 void NFWrDat(uint8 dat) { OS_ENTER_CRITICAL(); NF_DPORT_OUT; NF_nWE_SET; NF_CLE_CLR; NF_nCS_CLR; NF_ALE_CLR; NF_nWE_CLR; NF_BUSY_END; // wait busy end FIO3SET |= (uint32)dat; NF_BUSY_END; // wait busy end NF_nWE_SET; OS_EXIT_CRITICAL(); }
//读数据 uint8 NFRdDat(void) {
uint8 Rdata; OS_ENTER_CRITICAL(); NF_DPORT_IN; NF_nWE_SET; NF_CLE_CLR; NF_ALE_CLR; NF_nCS_CLR; NF_nOE_CLR; NF_BUSY_END; // wait busy end
Rdata = (UINT8)( FIO3PIN ); NF_BUSY_END; NF_nOE_SET; OS_EXIT_CRITICAL(); return Rdata;
}
/********************************************************************************************************* ** 函数名: NF_ReadPage() ** 说 明: 读页面 *********************************************************************************************************/ void NF_ReadPage(uint32 Block, uint8 Page,uint8 *Buff) {
uint16 i, j; uint32 BlockPage; uint8 HAdd; uint8 MAdd; uint8 LAdd; uint8 *bufPt = Buff; //每块32页,每页512字节 Page &= 0x1F; //[Page = A9,A10,A11,A12,A13] //计算实际地址 BlockPage = (Block<<5) + Page; //[Block = A14 ...] LAdd = (unsigned char)(BlockPage & 0xFF); MAdd = (unsigned char)(BlockPage>>8 & 0xFF); HAdd = (unsigned char)(BlockPage>>16 & 0xFF); //读写NAND的时候,总线不可以变化,中断读写特殊寄存器可能引起总线跳变 OS_ENTER_CRITICAL();
NFWrCmd(0x00); NFWrAddr(0x00); //NFWriteAdd(HAdd, MAdd, LAdd); NFWrAddr(LAdd); NFWrAddr(MAdd); NFWrAddr(HAdd);
//The 528 bytes of data within the selected page are //transferred to the data registers in less than 12us(tR). for (j=0; j<10; j++); //wait tWB(100ns)/////??????
NF_BUSY_END; // Wait tR(max 12us)
for (i=0;i<512;i++) { *bufPt++ = NFRdDat(); // Read one page }
OS_EXIT_CRITICAL();//开中断 }
/********************************************************************************************************* ** 函数名: NF_WritePage() ** 说 明: 写页面 *********************************************************************************************************/ uint8 NF_WritePage(uint32 Block, uint8 Page, uint8 *Buff) {
uint8 Status; uint8 HAdd; uint8 MAdd; uint8 LAdd; uint16 i; uint32 BlockPage; uint8 *bufPt = Buff;
//每块32页,每页512字节 Page &= 0x1F; //[Page = A9,A10,A11,A12,A13] //计算实际地址 BlockPage = (Block<<5) + Page; //[Block = A14 ...] LAdd = (unsigned char)(BlockPage & 0xFF); MAdd = (unsigned char)(BlockPage>>8 & 0xFF); HAdd = (unsigned char)(BlockPage>>16 & 0xFF);
//读写NAND的时候,总线不可以变化,中断读写特殊寄存器可能引起总线跳变 OS_ENTER_CRITICAL();//关中断
NFWrCmd(0x80); NFWrAddr(0x00); //NFWriteAdd(HAdd, MAdd, LAdd); NFWrAddr(LAdd); NFWrAddr(MAdd); NFWrAddr(HAdd); for (i=0;i<512;i++) { NFWrDat(*bufPt++); // Write one page to NFM from buffer }
NFWrCmd(0x10); //Read Staus Register while (1) {//Device Operation --- BIT6 NFWrCmd(0x70); Status = NFRdDat(); if (Status & (1<<6)) {//Busy : "0" Ready : "1" break; } } //Read Staus Register //Total Pass/Fail -- BIT0 NFWrCmd(0x70);; Status = NFRdDat(); if (Status & (1<<0)) {//Fail : "1" OS_EXIT_CRITICAL();//开中断 return 0; } else {//Pass : "0" OS_EXIT_CRITICAL();;//开中断 return 1; } } |