Problem with 2864 EEPROM

Hello, I a beginner and trying to program a 2864 type parallel EEPROM. I want to write simple data to 2 locations in parallel EEPROM memory. After writing, I want to read this data and display it on the serial monitor. Unfortunately, the serial monitor displays both locations as the same data "2" - not as "1" and "2". Where is the mistake? I use Arduino Mega board.

Thanks Jurek

#define CS  2
#define OE  3
#define WE  4
#define IO  PORTC
#define AD0 5
#define AD1 6
#define AD2  7
#define AD3  8
#define AD4  9
#define AD5  10
#define AD6  11
#define AD7  12
#define AD8  13
#define AD9  22
#define AD10 23
#define AD11 24
#define AD12 25

void setup() {
  // put your setup code here, to run once:
  
  // Configure control pins
  pinMode(CS, OUTPUT);
  pinMode(WE, OUTPUT);
  pinMode(OE, OUTPUT);

  digitalWrite(OE, HIGH);
  digitalWrite(WE, HIGH);
  digitalWrite(CS, HIGH);
  
  // Configure data pins
  DDRC = 0x00;

  // Configure address pins
  pinMode(AD0, OUTPUT);
  pinMode(AD1, OUTPUT);
  // Set remaining address pins to LOW
  for(int i=AD2; i<=AD12; i++) {
    pinMode(i, OUTPUT);
    digitalWrite(i, LOW);
  }

  // Initialize serial communication
  Serial.begin(9600);
}

void loop() {
  
  // **************************************************
  // Write data 0b1 (1) to data location 1
  // **************************************************

  // Configure the control pins 
  digitalWrite(OE, HIGH);
  digitalWrite(WE, HIGH);
  digitalWrite(CS, LOW);
  
  // Set our data on the IO port and configure IO as output
  DDRC = 0xFF;
  IO = 0b1;

  // Set the address pins
  digitalWrite(AD0, HIGH);
  digitalWrite(AD1, LOW);

  // Perform the cycle
  digitalWrite(WE, LOW);
  delay(5);
  digitalWrite(WE, HIGH);
  digitalWrite(CS, HIGH);

 
  // **************************************************
  // Write data 0b10 (2) to data location 3
  // **************************************************

  // Configure the control pins 
  digitalWrite(OE, HIGH);
  digitalWrite(WE, HIGH);
  digitalWrite(CS, LOW);
  
  // Set our data on the IO port and configure IO as output
  DDRC = 0xFF;
  IO = 0b10;

  // Set the address pins
  digitalWrite(AD0, HIGH);
  digitalWrite(AD1, HIGH);

  // Perform the cycle
  digitalWrite(WE, LOW);
  delay(5);
  digitalWrite(WE, HIGH);
  digitalWrite(CS, HIGH);




  // **************************************************
  // Read data from data location 1
  // **************************************************

  // Configure the control pins 
  digitalWrite(OE, HIGH);
  digitalWrite(WE, HIGH);
  digitalWrite(CS, LOW);
  
  // Configure data as input
  DDRC = 0x00;

  // Set the address pins
  digitalWrite(AD0, HIGH);
  digitalWrite(AD1, LOW);

  // Perform the read cycle
  digitalWrite(OE, LOW);
  delay(5);
  unsigned char data1 = PORTC;
  digitalWrite(OE, HIGH);
  digitalWrite(CS, HIGH);
  
  // Print the read data
  Serial.print("Data read from memory location 1: ");
  Serial.println(data1, HEX);
  delay(1000);  // Add a delay so the output is more readable



  // **************************************************
  // Read data from data location 3
  // **************************************************

  // Configure the control pins 
  digitalWrite(OE, HIGH);
  digitalWrite(WE, HIGH);
  digitalWrite(CS, LOW);
  
  // Configure data as input
  DDRC = 0x00;

  // Set the address pins
  digitalWrite(AD0, HIGH);
  digitalWrite(AD1, HIGH);

  // Perform the read cycle
  digitalWrite(OE, LOW);
  delay(5);
  unsigned char data3 = PORTC;
  digitalWrite(OE, HIGH);
  digitalWrite(CS, HIGH);
  
  // Print the read data
  Serial.print("Data read from memory location 3: ");
  Serial.println(data3, HEX);
  delay(1000);  // Add a delay so the output is more readable
}

schematic please.

1 Like

Word problems give me a headache as do frizzy drawings. Please post an annotated schematic showing what you want to build. Include all connections, power, ground and power sources.

This project has no specific purpose, beyond educational value - I simply want to learn how to program parallel memory and use it for future projects. I started with a simple task, that is to write the values ​​"1" and "2" in specific places in this memory, for example, 1 and 3. For this purpose, I use the A0 and A1 addresses - the rest to ground. After writing these values, I expect the serial monitor to display this data with the information: location / value. When I run the program, a problem occurs - the serial monitor returns info that the same value is recorded in both memory locations. Thanks.

Follow these steps:
A: Keep aside the Pin/Signal diagram (Fig-1) of 28C64 parallel EEPROM.
28C64EEPROMPic
Figure-1: Pin diagram./signal of 28C64 EEPROM

B: Power down the MEGA and then carry out the following steps:
1. Place the memory chip of Fig-1 in a good Breadboard.
2. Connect Pin-28 with 5V of MEGA.
3. Connect Pin-14 with GND-pin of MEGA.
4. Leave Pin-1, 26 open circuited.
5. Connect all A2-A12 lines with Pin-14 (GND potential) of EEPROM.
6. Connect I/O0-I/O7 lines respectively with DPin-22 - DPin-29 (PORTA) of MEGA.
7. Connect CE/, WE/, OE/ pin respectively with DPin-53, 52, 51 (PB0, PB1, PB2 of PORTB) of MEGA.

8. Connect A0, A1 pin respectively with DPin-36, 37 (PC0, PC1 of PORTC) of MEGA.
9. Recheck the connections of the EEPROM with MEGA.

C: Power up MEGA. Touch the EEPROM and check that it is cool. Now, carry out the following steps.
1. Upload the following sketch in MEGA.

void setup()
{
  Serial.begin(9600);

  //---- initialization----------------------------------
  pinMode(37, OUTPUT);   //A0 line = PC0
  pinMode(36, OUTPUT);  //A1 line = PC1

  DDRA = 0b11111111; //Data lines are output initially; PORTA

  pinMode(53, OUTPUT);   //CE/ line ; PB0  
  pinMode(52, OUTPUT); //WE/ line ; PB1
  pinMode(51, OUTPUT); //OE/ line ; PB2

  PORTB = 0b11111111;  //-- CE/, WE/, OE/ control lines are made high

  //----- writing process into EEPROM---
  digitalWrite(37, LOW); //A0 = 0
  digitalWrite(36, LOW);  //A1 = 0

  digitalWrite(53, LOW);    //CE/ line LOW
  delayMicroseconds(100);  //to settle transient

  PORTA = 0x23;   //assert data 0x23
  delayMicroseconds(100);  //to settle transient

  digitalWrite(52, LOW);    //put LOW on WE/ line
  delay(5);   //wait for twc (max write -cycle delay)
  digitalWrite(52, HIGH);

  //--- reading  data back-----
  DDRA = 0b00000000;  //data lines are inputs
  delayMicroseconds(100);  //to settle transient
  digitalWrite(51, LOW);  //OE/ line is LOW
  delayMicroseconds(100);  //to settle transient

  byte myData = PINA;    //get data
  Serial.println(myData, HEX);   //check that Serial Monitor shows 23
}

void loop() {}

2. Press RESET Button of MEGA.
3. Open Seral Monitor.
4. Check that Serial Monitor shows: 23.
5. Perform read/write at location 0x0003 of EEPROM with data 0xD7.

1 Like

@jurekp

You are reading the output port
unsigned char data1 = PORTC;
Should be
unsigned char data1 = PINC;

4 Likes

Thanks a lot! It works perfect now. Could you please explain the difference? I'm afraid it's not clear for me as should be.

He did explain. You are reading an output. Reading is an input operation... you would write to an output.

By the way, you don't need to use mysterious direct port access for this application. digitalRead() and digitalWrite() can easily do the job.

There isn't much doubt, it would confuse you less.

The following diagram (Fig-1) may help you to understand the physics/architecture behind "data reading from the pins of an input port" and "data writing onto the pins of an output port".


Figure-1:

1 Like

Yes, and also the MCU data sheet...

1 Like

@GolamMostafa Thanks a lot for the code. I'm not sure if this is what I needed. I recreated your code and indeed the serial monitor returns "23", but what does this mean? Are these 2 and 3 written in different memory locations? Or is it one number, under one address? Could you explain?

I'll tell you what I would always do in a case like this. Simplify. Try to read/write one memory location.

Then get fancy, knowing it works...

Be careful not to write code that burns the same location 1,000,000 times until it fails. Ask me how I know.

2 Likes

Please make one, using pen and paper.

I did, and It worked as expected.

Yes, data-sheet is clear about it.

Well that is more than half the battle. Spend some time on it, you can succeed.

A2-A12 lines are grounded. Now, A0 and A1 lines will hit the following locations of the EEPROM.

A12 - A2    A1 A0       EEPROM Location Address
0 ....0     0   0       0000 in hex base
0 ....0     0   1       0001 in hex base
0 ....0     1   0       0002  in hex base
0 ....0     1   1       0003  in hex base

I have written 23 (in hex base) into location with address 0000 (in hex base)

Read data sheets of 28C64 and get the following procedures of writing an 8-bit data into a memory location:
1. Keep HIGH on CE/, WE/, and OE/ pins of EEPROM
2. Assert address on the address lines of EEPROM
3. Assert LOW on CE/ pin to latch the address.
4. Put 8-bit data on data lines of the EEPROM.
5. Put LOW on WE/ pin.
6. Wait for 5 ms (max) for the data byte to get fused into the target location. Alternately, you can use Polling strategy allowing the EEPROM to take as much as it needs to get written the data into the target location (according to data sheets it is 2 ms).

7. Read data sheets to know the procedures of reading data back from location 0x0000 (in hex base).

1 Like

Not quite. You can (should) release WE/ immediately. However you need to wait before you program the next location.

7. Read data sheets to know the procedures of reading data back from location 0x0000 (in hex base).

That's easy, just pull CS/ low, data appears on the I/O lines.

Yes, exactly - I just studying your code:

  //----- writing process into EEPROM---
  digitalWrite(37, LOW); //A0 = 0
  digitalWrite(36, LOW);  //A1 = 0

So, by changing the memory location address, I can write the remaining 3 using the binary combination A1-A0. Will try! Thanks for this invaluable help.

You should be able to, but as the chip was used in PC MB, many variants were produced that don't produce the status signal needed for polling.

I think this explains it fairly well.

2 Likes