[Apologies for recreating this question - I had it in the wrong category, so I moved it to the right category]
Hi everyone,
I have just bought an Arduino Mega (based on 2560 chip) and some SST39SF010A DIP memory. I would like to program the memory to store ALU data, since I will be using flash memory as my ALU.
I have been following this guide to program the memory. Most of my code has been copied line-by-line, but I made a few adjustments:
- I defined CE, even though it will always be low, just for completeness
- I only defined addresses up to RA14, since my ALU will only use A8-A0 and the chip software only uses A14-A0
- Because of (2), I use integers instead of longs. Still unsigned.
- I changed the MEGA pins that connect to the data and address pins:
- A14-A0 = pins 44-30
- D7-D0 = pins 13-6
- WE = 2, OE = 3, CE = 4
However, none of these changes should create any issue. But it does!
It looks to me like reading the flash works (because by default all bits are on), but either writing or erasing the flash does not work (or both!).
I have attached my (mostly copied) code below. Please let me know if you would like anything else from me. Thanks!
// Code is copied from https://mint64.home.blog/2018/07/30/parallel-nor-flash-eeprom-programmer-using-an-arduino-part-2-arduino-code-and-serial-comms/
// Thanks heaps!
#define WE 2
#define OE 3
#define CE 4
#define RA0 30
#define RA14 44
#define RD0 6
#define RD7 13
void setup() {
setDigitalIn();
setControlPins();
setAddrPinsOut();
Serial.begin(9600);
delay(2);
Serial.println("Ready to go!");
}
void loop(){
if(Serial.available()){
readSerialCommand(Serial.read());
}
}
void readSerialCommand(byte in){
if(in == 'E'){
Serial.println("Erasing data");
eraseData();
Serial.println("Erased!");
}else if(in == 'R'){
Serial.println("Reading data");
byte in = readData(0x0000);
Serial.print("Data at address 0 is: ");
Serial.println(in);
}else if(in == 'W'){
Serial.println("Writing data");
writeData(0x04, 0x0000);
Serial.println("Written!");
}else{
Serial.println("Invalid command!");
}
}
void setAddrPinsOut(){
for(int i = RA0; i < RA14; i++){
pinMode(i, OUTPUT);
digitalWrite(i, LOW);
}
}
void setDigitalOut(){
for(int i = RD0; i < RD7; i++){
pinMode(i, OUTPUT);
}
}
void setDigitalIn(){
for(int i = RD0; i < RD7; i++){
pinMode(i, INPUT);
}
}
void setControlPins(){
pinMode(WE, OUTPUT);
pinMode(OE, OUTPUT);
pinMode(CE, OUTPUT);
digitalWrite(WE, HIGH);
digitalWrite(OE, HIGH);
digitalWrite(CE, LOW);
}
void setByte(byte out){
for(int i = 0; i < 8; i++){
digitalWrite(RD0 + i, bitRead(out, i));
}
}
void setAddress(unsigned int address){
for(int i = 0; i < 15; i++){
digitalWrite(RA0 + i, bitRead(address, i));
}
}
byte readByte(){
byte ret = 0;
for(int i = 0; i < 8; i++){
if(digitalRead(RD0 + i)) bitSet(ret, i);
}
return ret;
}
byte readData(unsigned int address){
byte in;
setDigitalIn();
setAddress(address);
digitalWrite(OE, LOW);
delayMicroseconds(1);
in = readByte();
digitalWrite(OE, HIGH);
return in;
}
void writeByte(byte out, unsigned int address){
setAddress(address);
setByte(out);
digitalWrite(WE, LOW);
delayMicroseconds(1);
digitalWrite(WE, HIGH);
}
void eraseData(){
setDigitalOut();
writeByte(0xAA, 0x5555);
writeByte(0x55, 0x2AAA);
writeByte(0x80, 0x5555);
writeByte(0xAA, 0x5555);
writeByte(0x55, 0x2AAA);
writeByte(0x10, 0x5555);
delay(100);
}
void writeData(byte out, unsigned int address){
setDigitalOut();
writeByte(0xAA, 0x5555);
writeByte(0x55, 0x2AAA);
writeByte(0xA0, 0x5555);
writeByte(out, address);
delayMicroseconds(30);
}
