??? 06/08/07 09:59 Read: times |
#140413 - external flashmemory interfacing for data storage |
Hi
I have a problem in interfacing AM29F016D flash memory chip with AT89S52. here I am giving code written in C (SDCC). #define MEM_OE P2_0 #define MEM_WE P2_1 #define MEM_RY_BY P2_2 #define MEM_RESET P2_3 #define MEM_CE P2_4 #define LATCH1 P2_5 #define LATCH2 P2_6 #define LATCH3 P2_7 #define MDATA P0 void hardware_rst(void) // takes flash into reading array mode { MEM_CE = 1; MEM_OE = 1; MEM_RESET = 0; _asm nop nop nop nop nop nop nop nop _endasm; MEM_RESET = 1; _asm nop nop nop nop nop nop nop nop _endasm; while(!MEM_RY_BY); } // MEMORY FUNCTION T0 LATCH ADDRESS TO FLASH void latch_address(unsigned long address) { unsigned char lda1,lda2,lda3; lda3 = (address & 0x00ff0000)>>16; lda2 = (address & 0x0000ff00)>>8; lda1 = address & 0x000000ff; LATCH1 = 0; LATCH2 = 0; LATCH3 = 0; MDATA = lda1; //lsb _asm nop nop nop nop _endasm; LATCH1 = 1; _asm nop nop nop nop _endasm; LATCH1 = 0; MDATA = lda2; _asm nop nop nop nop _endasm; LATCH2 = 1; _asm nop nop nop nop _endasm; LATCH2 = 0; MDATA = lda3; //msb _asm nop nop nop nop _endasm; LATCH3 = 1; _asm nop nop nop nop _endasm; LATCH3 = 0; } //FUNCTION TO READ ARRAY DATA FROM FLASH unsigned char flash_read(unsigned long address) { unsigned char datta; latch_address(address); P0 = 0xff; MEM_WE = 1; //WRITE ENABLE MEM_CE = 0; //CHIP ENABLE MEM_OE = 0; // OUTPUT ENABLE _asm nop nop nop nop nop nop nop nop _endasm; datta = MDATA; MEM_OE = 1; MEM_CE = 1; return(datta); } void write_command(unsigned long address,unsigned char cmd) { MEM_RESET = 1; latch_address(address); MEM_CE = 0; MEM_OE = 1; MEM_WE = 0; MDATA = cmd; _asm nop nop _endasm; MEM_WE = 1; MEM_CE = 1; } void flash_eraseall(void) { //hardware_rst(); while(!MEM_RY_BY); write_command(0x00000555,0xAA); write_command(0x000002AA,0x55); write_command(0x00000555,0x80); write_command(0x00000555,0xAA); write_command(0x000002AA,0x55); write_command(0x00000555,0x10); while(MEM_RY_BY); while(!MEM_RY_BY); } void flash_write(unsigned long address,unsigned char dat) { hardware_rst(); while(!MEM_RY_BY); write_command(0x00000555,0xAA); write_command(0x000002AA,0x55); write_command(0x00000555,0xA0); write_command(address,dat); while(MEM_RY_BY); while(!MEM_RY_BY); } void main(void) { unsigned char j; unsigned int i; unsigned long mempointer; for(j=0;j<200;j++) // VCC setup time (>50us) for flash // memory (AM290F016D)-Tvcs { _asm nop nop _endasm; } // Serial port configuration TH1 = 256 - ((FCLK / 384)/BAUD);//1200 baudrate TMOD = 0x20; //8 bit auto reload TR1 = 1; SCON = 0x50; //8bit UART set by TIMER1 for serial_0 RI = 0; //Flash memory defaults for TTL standby state hardware_rst(); MEM_CE = 1; MEM_RESET = 1; TI = 0; SBUF = 'R'; while(!TI); flash_eraseall(); mempointer = 0x00000000; // ********flash write loop************* for(i=0;i<255;i++) //<<<<<<< problem is here<<<<< flash_write(mempointer++,i); TI = 0; SBUF = 'S'; while(!TI); while(1); } the above code is working fine when variable "i" in flash write loop is less than 255 and hangs when "i" is more i.e. (i < 260). I found that when loop runs less than 255 its working fine and controller is hanging when loop runs more than 260. i.e. flash write function is failing. pl post replys to solve this problem as soon as possible thanks P.Ravi |
Topic | Author | Date |
external flashmemory interfacing for data storage | 01/01/70 00:00 | |
You should know how to post code by now | 01/01/70 00:00 | |
which version of sdcc? | 01/01/70 00:00 | |
code posted | 01/01/70 00:00 | |
Hmmm... | 01/01/70 00:00 | |
I used Charles Bannister's trick | 01/01/70 00:00 | |
As soon as possible? | 01/01/70 00:00 | |
As soon as possible? Maybe he is in bed! | 01/01/70 00:00 | |
I am very sorry.... | 01/01/70 00:00 | |
sorry for being impatient... | 01/01/70 00:00 | |
Thanks![]() | 01/01/70 00:00 |