Go Down

Topic: Arduino EEPROM Programmer: Burning a ROM image (Read 6 times) previous topic - next topic

legendmythe

Hi,
I was working on a little electronics project: a z80 computer, while I was doing that I needed to program an EEPROM, after seeing the price of a universal programmer, I decided to make my own using an arduino.

So far I managed to read the EEPROM and to erase it using my Arduino, here you can see my code for writing 0's to the EEPROM. Now I want to burn a binary image, let's call it "data.rom", to the EEPROM. I was thinking of using serial communication and then use some sort of script that reads data.rom and that passes byte per byte to the arduino through the serial monitor. The arduino then stores the byte in "D" (see code) and then writes that byte, and then wait for a new byte and so on.

But I'm not so familiar with coding for the arduino, neither with serial communication, so I was hoping someone could help me.

Code: [Select]
/*
EEPROM Programmer
*/
#define memsize 8192

int STS   = 13;  // Status Indicator

// The pins that are used for the address bus
int AP[13] = {24,26,30,32,36,38,42,44,48,50,47,51,53};
// Used by the code to decode an address
int AD[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
// The pins used for the Data bus
int DP[8]  = {23,25,29,31,35,37,41,43};
// Used by the code to decode a byte
int DD[8]  = {0,0,0,0,0,0,0,0};

// Pins used for the control bus
int CE  = 6;
int OE  = 4;
int WE  = 2;

int i;          // Used by for-loops
int A;         // Used to store the current address in the main loop
int D;         // Used to store the byte that will be written in that cycle to address A

void setup()
{

  Serial.begin(9600);
  Serial.println("Writing EEPROM...");
 
  // Led that shows activity
  pinMode(STS,   OUTPUT);
 
  // Setup Address Pins
  for (i=0;i<16;i++)
  {
    pinMode(AP[i],OUTPUT);
  }
 
  // Setup Data Pins
  for (i=0;i<8;i++)
  {
    pinMode(DP[i],OUTPUT);
  }
 
  // Setup Control Pins
  pinMode(CE, OUTPUT);
  pinMode(WE, OUTPUT);
  pinMode(OE, OUTPUT);
 
  // Setup Chip
  digitalWrite(CE, LOW);
  digitalWrite(WE, LOW);
  digitalWrite(OE, HIGH);


  // Loop that writes Byte per byte
  for (A=0;A<memsize;A++)
  {
    // D is the Byte that will be written to the current address(A).
    D=0;
    digitalWrite(STS,HIGH);  //Signal that we're writing.

    // Setup Address Pins
    for (i=0;i<13;i++)
    {
      if((A&bit(i))>0)
      {
        AD[i]=HIGH;
      } else {
        AD[i]=LOW;
      }     
      digitalWrite(AP[i],AD[i]);
    }
   
    // Setup Control bus
    digitalWrite(OE,LOW);   // Reads Disabled
    delay(1);               // Give the EEPROM some time to catch up
    digitalWrite(CE,HIGH);  // Chip Enable
    digitalWrite(WE,HIGH);  // Write Enabled
   
    // Setup Data Pins
    for (i=0;i<8;i++)
    {
      if((D&bit(i))>0)
      {
        DD[i]=HIGH;
      } else {
        DD[i]=LOW;
      }     
      digitalWrite(DP[i],DD[i]);
    }
   
    // Write data (D)
    digitalWrite(WE,LOW);      // Write Disabled
    digitalWrite(CE,LOW);      // Chip Disabled
    digitalWrite(OE,HIGH);     // Reads Enabled
    delay(1);
   
   digitalWrite(STS,LOW);      // Signal that we're waiting
   
  }
 
    // We got through the loop, signal that the write was succesfull
    Serial.println("Done...");
}

void loop() {
  // Small loop to show that data was written and device can be removed
  digitalWrite(STS, HIGH);   
  delay(1000);             
  digitalWrite(STS, LOW);   
  delay(1000);             
}

gateway

Hi,

I'm not familiar with programming EEPROMs, but seems to me you're almost there.
First I would recommend replacing this:
Code: [Select]

      if((A&bit(i))>0)
      {
        AD[i]=HIGH;
      } else {
        AD[i]=LOW;
      }     
      digitalWrite(AP[i],AD[i]);

with:
Code: [Select]

      digitalWrite(AP[i], bitRead(A,i));

and losing the AD array all together.
Same can be done with the D loop and DD array.

As for reading serial data, you've already managed to use Serial communications, so all you would need (besides from perhaps something like error correction) would be replacing the line:
Code: [Select]

    D=0;

with something like:
Code: [Select]

    while (Serial.available()==0) delay(1);
    D = Serial.read();


That would assume you would always send the full content of the EEPROM (8192 bytes) through the serial port.

Good luck!

Regards Dennis

legendmythe

#2
Oct 29, 2012, 09:15 am Last Edit: Oct 29, 2012, 09:30 am by legendmythe Reason: 1
Thanks for the reply!

I did what you told me and I added the following code:
Code: [Select]
D = Serial.read() - '0';   // "-0" to convert ASSCI to the actual data But for some reason the program does this:
-It asks my data, I pass it for example 0
-It stores that data at the current address A
-But then it also stores 0xDD and 0xDA at addresses (A+1) and (A+2)


After a bit of think I realized what was wrong: The serial monitor first sends D, but I also passed "\n" and '\r' so it passes that too, :) So if anyone else has this problem, in the serial monitor there's a small box saying something like also send newline and carriage return set that to no newline.

Thanks for all the help, but I still got 1 question: Is it possible to write some sort of program that sends the data that it reads from some file through the serial port so that I don't have to type all the data in the serial monitor because that could save me a lot of time.

PaulS

Quote
Is it possible to write some sort of program that sends the data that it reads from some file through the serial port so that I don't have to type all the data in the serial monitor because that could save me a lot of time.

Of course it is. What OS are you using? What language(s) are you familiar with? Depending on OS and language, this ranges from nearly trivial (C# on Win7 could be used (by me, anyway) to create such a program in under an hour) to challenging.

legendmythe

I'm using windows 7 64 bit and I'm familiar with C, but I don't know anything about sending data through a serial port... I can make a program that reads a file and all, but how do I send a byte over a serial port in C? I'm using Codeblocks with MinGW compiler

Go Up