Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

At49f040 Flash Interface

Status
Not open for further replies.

Help

Advanced Member level 2
Joined
Feb 15, 2005
Messages
617
Helped
7
Reputation
14
Reaction score
3
Trophy points
1,298
Activity points
7,065
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.
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

  • waveforms.JPG
    waveforms.JPG
    115.8 KB · Views: 64
Last edited:

Dear All,

I still can't get the correct data from the flash memory. I always received 0x10 data at 0x0000 (manufacture ID) and at 0x0001 (device ID).

Is there anyone can help me?

Thank you.
 

It seems that you used 8051 based MCU and the P0 has external pull-up resistors.
You have to set 1 to output for reading correct signals.
Ex:
Code:
  PORT0_DATABUS = 0xff;
  nop_();
  nop_();
  GetData = PORT0_DATABUS;
 
  • Like
Reactions: Help

    Help

    Points: 2
    Helpful Answer Positive Rating
Hallo Yager,

Thanks for your reply. Ya, finally it work.

You are rite. The 8051 based MCU P0 has external pull-up resistors. May i know why if P0 has external pull-up resistors then we have to set the output to 1 then only can read the signal? As i know P0 don't have internal pull-up resistor. I didn't face this problem before but this the first time.

Seem like P0 allowing it to be used for both address and data. I will try to reduce the port pin using 74HC573 to latch the address. In this case should i put a pull-up resistors on it?

Thanks for your advice.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top