我用的是K9F2808U0C NAND FLASH芯片。各位大侠,帮忙看看 //*****读单字节子程序 //* Area A Bytes 0-255 //* Area B Bytes 256-511 u8 NandReadData(u32 address) { u8 data_; Nand_CE_Active(); GPIO_Config(GPIO2, A23_P27, GPIO_IN_TRI_CMOS); if ( (address % PAGE_DATA_SIZE) >= PAGE_DATA_SIZE/2 ) NandCommand(Nand_AreaB); /* First Half Page - Area B*/ else NandCommand(Nand_AreaA); /* Second Half Page - Area A*/ NandSendAddress(address); NOP(); //tWB = 100ns. mDelay(3); //wait tPROG 200~500us; while(!Nand_Ready()); // Read RnB Pin, Wait for Ready State data_ = NandDataOutput(); UART_ByteSend(UART0, &data_); //串口显示 Nand_CE_noActive(); return data_; }
//******写单字节子程序 u8 NandWriteByte (u32 address, u8 data) { Nand_CE_Active(); GPIO_Config(GPIO2, A23_P27, GPIO_IN_TRI_CMOS); if ( (address % PAGE_DATA_SIZE) >= PAGE_DATA_SIZE/2 ) NandCommand(Nand_AreaB); /* Select Area B*/ else NandCommand(Nand_AreaA); /* Select Area A*/ NandCommand(Nand_PageProgram); //80H NandSendAddress(address); NandDataInput(data); NandCommand(Nand_EndPageProg); //10H NOP(); //tWB = 100ns. mDelay(3); //wait tPROG 200~500us; while(!Nand_Ready()); // Read RnB Pin, Wait for Ready State while(!(NandReadStausRegister()&(NandReady|!NandError))); //读状态, UART_ByteSend(UART0, &data); //串口显示 //mDelay(100); Nand_CE_noActive(); } //******块擦除子程序 u32 NandBlockErase(u32 address) { u8 Staus; Nand_CE_Active(); GPIO_Config(GPIO2, A23_P27, GPIO_IN_TRI_CMOS); NandCommand(Nand_BlockErase); //60H NandSendCAddress(address); //address NandCommand(Nand_ConfirmErase); //D0H while(!Nand_Ready()); //wait R/B=1? Staus=NandReadStausRegister(); if(Staus&0x1) //判断I/O0状态 { return 0; //擦除不成功 } else { return 1; //擦除成功 } Nand_CE_noActive(); }
int main(void) { RCCU_MCLKConfig(RCCU_DEFAULT); // MCLK = RCLK RCCU_FCLKConfig(RCCU_RCLK_2); // FCLK = RCLK/2 RCCU_PCLKConfig(RCCU_RCLK_4); // PCLK = RCLK/4 RCCU_PLL1Config(RCCU_PLL1_Mul_12, RCCU_Div_2); // 48MHz PLL @ 16MHz XTAL
while (RCCU_FlagStatus(RCCU_PLL1_LOCK) == RESET); // Wait for PLL to Lock RCCU_RCLKSourceConfig(RCCU_PLL1_Output); // Select PLL for RCLK ...... ...... ...... 然后在下面程序里调用:
if(NandBlockErase(NFBlcokAddr)) //判断块擦除是否成功 { for(a=0;a<512;a++) { NandWriteByte (NFBlcokAddr, Wdata); //成功则开始写数据 NFBlcokAddr++; Wdata++; } for(a=0;a<512;a++) { NandReadData(NFBlcokAddr); NFBlcokAddr--; } } else { UART_StringSend(UART0, (u8 *)&"BlockErase is Error!");//擦除不成功提示出错。 } } |