改成总线方式,读ID,状态都正常,现在测试读写页面程序,遇到一些问题,请大家帮忙看看,谢谢
unsigned char nandFlashPageRead( unsigned int NandAddr, unsigned char *Buffer ) {
unsigned char NandStatus; unsigned short i; // for x8 NAND flash device, one page = 512 + 16 Bytes // uint32 NandAddr = nPage * 512 + nBlock * ( 512 * 32 ); uint32 StartColumn = 528 - (NandAddr & 0x1ff);
FIO2CLR1 |= (0x01 << 0); OS_ENTER_CRITICAL(); NF_nCS_CLR; if ( ( NandAddr >> 8 ) & 0x1 ) { NFWrCmd( NAND_CMD_AREA_B ); //begin from "B" half page } else { NFWrCmd( NAND_CMD_AREA_A ); //begin from "A" half page }
NFWrAddr( ( uint16 ) ( NandAddr & 0xff ) ); //column address NFWrAddr( ( uint16 ) ( ( NandAddr >> 9 ) & 0xff) ); //low block address NFWrAddr( ( uint16 ) ( ( NandAddr >> 17 ) & 0xff) ); //high block address //read NAND status register NFWrCmd( NAND_CMD_RD_STATUS );
//wait until write operation success do { NandStatus = NFRdDat(); } while (!(NandStatus & 0x40)); NFWrCmd( NAND_CMD_RD_DONE );
for ( i = 0; i < StartColumn; i++ ) Buffer = NFRdDat();
NF_nCS_SET; OS_EXIT_CRITICAL(); FIO2SET1 |= (0x01 << 0); return NandStatus; }
unsigned char nandFlashPageWrite( unsigned int NandAddr , unsigned char *Buffer ) { unsigned char NandStatus = 0x0; unsigned int i; // for x8 NAND flash device, one page = 512 + 16 Bytes // uint32 NandAddr = nPage * 512 + nBlock * ( 512 * 32 );
unsigned short StartColumn = 528 - (NandAddr & 0x1ff);
OS_ENTER_CRITICAL(); //NF_nCS_CLR; if ( ( NandAddr >> 8 ) & 0x1 ) { NFWrCmd( NAND_CMD_AREA_B ); //begin from "B" half page } else { NFWrCmd( NAND_CMD_AREA_A ); //begin from "A" half page } NFWrCmd( NAND_CMD_PAGEPROG_I ); //program command 1st cycle with 80h NFWrAddr( ( uint16 ) ( NandAddr & 0xff ) ); //column address NFWrAddr( ( uint16 ) ( ( NandAddr >> 9 ) & 0xff) ); //low block address NFWrAddr( ( uint16 ) ( ( NandAddr >> 17 ) & 0xff) ); //high block address
for ( i = 0; i < StartColumn; i++ ) NFWrDat( Buffer );
NFWrCmd( NAND_CMD_PAGEPROG_II );//confirm program with 10h //read NAND status register NFWrCmd( NAND_CMD_RD_STATUS ); //wait until write operation success do { NandStatus = NFRdDat(); } while (!(NandStatus & 0x40)); NFWrCmd( NAND_CMD_RD_DONE ); // NF_nCS_SET; OS_EXIT_CRITICAL();
return NandStatus;
}
void main() { .... .... for ( i=0; i<512; i++ ) inbuff = 0x59; NFlashState =nandFlashPageWrite(0,inbuff);
for (i =0; i<512; i++) { NFlashState = nandFlashPageRead(0, outbuff); sprintf(buf," %X ",outbuff); UART0WriteString((uint8 *) buf); } .... }
打印出来的结果如下: Start testing NandFlash2....
ID=EC73 lockEraseState=C0 0 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
现在我判断问题出在写页面出错,大家帮我看看,到底是什么原因出现这个问题的?如何解决,谢谢 |