我用MSP430单片机外挂K9F1208U0BNand Flash,读出ID为EC 74 A4 0C 和手册上EC 76 A5 0C不一样,另外查了几个BLOCK的坏快SPARE 6byte都不为0XFF,难道都是坏快?下面是一部分代码,有熟悉的大侠帮忙看看,谢谢! //写命令 void NandWr_Cmd( unsigned char cmd ) { P5DIR = 0XFF; //P5输出 ALE_Disable(); CE_Enable(); CLE_Enable(); RE_Disable(); WE_Enable(); P5OUT = cmd; WE_Disable(); CE_Disable(); CLE_Disable(); return; } //写地址 void NandWr_Addr(unsigned char address ) { P5DIR = 0XFF; CE_Enable(); CLE_Disable(); ALE_Enable(); RE_Disable(); WE_Enable(); P5OUT = address; WE_Disable(); CE_Disable(); ALE_Disable(); return; } //读一个字节 unsigned char NandRd_Data(void) { unsigned char databuf = 0; P5DIR = 0; CE_Enable(); //P5输入 RE_Enable(); databuf = P5IN; RE_Disable(); CE_Disable(); return(databuf); } //写一个字节 void NandWr_Data(unsigned char data) { P5DIR = 0XFF; CLE_Disable(); ALE_Disable(); CE_Enable(); WE_Enable(); P5OUT = data; WE_Disable(); CE_Disable(); return; } //*************************************************************************** //* Name: NandFlashSpareRead //* Input(s) : unsigned int NandAddr. //* unsigned char *Buffer. //* Returns : void //* Description : x8 NAND flash page write //* Because we are using a x8 NAND, the data width is 8bit (unsigned char *Buffer). //* *Buffer should contain 512 Bytes data and 16 Bytes ECC information //* Notes: NandAddr //* A0 - A7 column address //* A8 low/high half page selection //* A9 - A16 low block address //* A17 - A24 high block address //* *buffer //* |-----from startcolumn----->|---------->| one page //* data field spare field //*************************************************************************** void NandFlashSpareRead( unsigned long NandAddr , unsigned char *Buffer ) { unsigned char NandStatus; unsigned short i; // for x8 NAND flash device, each page has 16 Bytes for spare unsigned short StartColumn = 16 - (NandAddr & 0xf);
NandWr_Cmd( NAND_CMD_AREA_C ); //begin from "C" area NandWr_Addr( ( unsigned char ) ( NandAddr & 0xf ) ); //column address for spare field NandWr_Addr( ( unsigned char ) ( ( NandAddr >> 8 ) & 0xff) ); //Page & block address NandWr_Addr( ( unsigned char ) ( ( NandAddr >> 16 ) & 0xff) ); //Page & block address NandWr_Addr( ( unsigned char ) ( ( NandAddr >> 24 ) & 0xff) ); //Page & block address //read NAND status register NandWr_Cmd( NAND_CMD_RD_STATUS ); do { NandStatus = NandRd_Data(); }while(!(NandStatus & 0x40)); NandWr_Cmd( NAND_CMD_RD_DONE );
for ( i = 0; i < StartColumn; i++ ) Buffer = NandRd_Data();
} |