Help
Advanced Member level 2
Dear All,
I'm tried to direct interface the flash memory from uC. I have wrote a simple code to call out the manufacture ID and device ID but can't get the correct ID. For AT49F040 the manufacture ID is 0x1F and Device ID is 0x13.
Hope can get some advice from you all how to call the manufacturer id and device id.
Thanks. :smile:
I'm tried to direct interface the flash memory from uC. I have wrote a simple code to call out the manufacture ID and device ID but can't get the correct ID. For AT49F040 the manufacture ID is 0x1F and Device ID is 0x13.
Code:
#define PORT0_DATABUS P0
#define PORT1_ADDLOBYTE P1
#define PORT2_ADDHIBYTE P2
sbit A16 = P3^2;
sbit A17 = P3^3;
sbit A18 = P3^4;
sbit CE = P3^5;
sbit WE = P3^6;
sbit OE = P3^7;
void nop_(void)
{
unsigned char x=0;
x++;
x++;
x++;
}
void flash_wr(const unsigned int add, const unsigned char value)
{
OE = 1;
WE = 1;
CE = 1;
A16 = 0;
A17 = 0;
A18 = 0;
PORT1_ADDLOBYTE = add%0x100;
PORT2_ADDHIBYTE = add/0x100;
WE = 0;
CE = 0;
PORT0_DATABUS = value;
nop_();
nop_();
WE = 1;
CE = 1;
}
unsigned char flash_rd(const unsigned int add)
{
unsigned char GetData=0;
WE = 1;
CE = 1;
OE = 1;
A16 = 0;
A17 = 0;
A18 = 0;
PORT1_ADDLOBYTE = add%0x100;
PORT2_ADDHIBYTE = add/0x100;
CE = 0;
OE = 0;
nop_();
nop_();
GetData = PORT0_DATABUS;
nop_();
nop_();
CE = 1;
OE = 1;
return GetData;
}
void flash_cmd(const unsigned char cmd)
{
XBYTE_flash_wr(0x5555, 0xAA);
XBYTE_flash_wr(0x2AAA, 0x55);
XBYTE_flash_wr(0x5555, cmd);
}
unsigned int flash_id(void)
{
unsigned int flash_id=0;
unsigned char id=0;
/* Product Id Entry mode */
flash_cmd(0x90);
printf("\n\nCheck manufacturer: ");
/* check: manufacturer code at 0000 */
id = flash_rd(0x0000);
putchar(id);
printf("\n\nCheck device\n\n");
/* check: devcie code at 0001 */
id = flash_rd(0x0001);
putchar(id);
putchar('\n');
/* @0000: manufacturer, @0001: device */
flash_id = XBYTE_flash_rd(0x0000) << 8 | XBYTE_flash_rd(0x0001);
/* Exit from Product Id */
flash_cmd(0xF0);
return flash_id;
}
Hope can get some advice from you all how to call the manufacturer id and device id.
Thanks. :smile:
Attachments
Last edited: