DerTrueForce wrote:
That datasheet you're looking at isn't the same as the one I have, at least in terms of layout. I got mine from the Microchip site.
The write-protection sequences haven't changed, though, so it might not be important.
I think you just have to make sure that you write that sequence, with nothing in between any of them. I have Ittiara run from RAM when I write to it, which does achieve that, but I actually did that because it'll crash the machine if I don't. The write time is much longer than a single cycle(even at 1MHz), and the EEPROM doesn't respond with valid data during that time.
Someone else here has done a similar thing, and he found that operating the AT28C256 too slowly caused some wierd results.
I'm back to trying to write to the 28c256. I've added a bypass capacitor across the EEPROM and also implemented the other changes to the circuit Dr. Jekyll suggested. I've tested each of my control, data, and address lines individually, and bit by bit, so I am 99% certain that my output methods are working correctly. However, I still fail to write to the EEPROM and/or disable the SDP.
I didn't see anything in the timing diagram that would indicate this, but do you have to poll whether the data is written while performing the SDP disable algorithm?
Here is my code, for reference:
Code:
#include "Arduino.h"
#define SHIFT_DATA 2
#define SHIFT_CLOCK 3
#define SHIFT_LATCH 4
#define DATA_PIN 5 // first data pin, 7 others will follow afterwards
#define WRITE_ENABLE 13
#define CHIP_ENABLE A0
#define OUTPUT_ENABLE A1
void high_pulse(int pin) {
digitalWrite(pin, LOW);
digitalWrite(pin, HIGH);
digitalWrite(pin, LOW);
}
void low_pulse(int pin) {
digitalWrite(pin, HIGH);
digitalWrite(pin, LOW);
digitalWrite(pin, HIGH);
}
void set_address(int address) {
shiftOut(SHIFT_DATA, SHIFT_CLOCK, MSBFIRST, address >> 8);
shiftOut(SHIFT_DATA, SHIFT_CLOCK, MSBFIRST, address);
high_pulse(SHIFT_LATCH);
}
void data_read_mode() {
for (int i = DATA_PIN; i <= DATA_PIN + 7; i++) {
pinMode(i, INPUT);
}
}
void data_write_mode() {
for (int i = DATA_PIN; i <= DATA_PIN + 7; i++) {
pinMode(i, OUTPUT);
}
}
int read_byte() {
int number = 0;
int temp;
for (int i = 0; i < 8; i++) {
temp = (int)digitalRead(DATA_PIN + i);
temp = temp << i;
number = number | temp;
}
return number;
}
int read(int address) {
data_read_mode();
set_address(address);
digitalWrite(WRITE_ENABLE, HIGH);
digitalWrite(CHIP_ENABLE, LOW);
digitalWrite(OUTPUT_ENABLE, LOW);
delayMicroseconds(2); //address to output delay(tACC)
return read_byte();
}
void write_byte(int address, int byte) {
set_address(address);
int temp;
for (int i = 0; i < 8; i++) {
temp = byte >> i;
temp = temp & 1;
digitalWrite(DATA_PIN + i, (bool)temp);
}
digitalWrite(CHIP_ENABLE, LOW);
digitalWrite(WRITE_ENABLE, LOW);
delayMicroseconds(1); //write pulse width(TWP)
digitalWrite(WRITE_ENABLE, HIGH);
digitalWrite(CHIP_ENABLE, HIGH);
delayMicroseconds(1);
}
void write_prepare() {
data_write_mode();
digitalWrite(OUTPUT_ENABLE, HIGH);
digitalWrite(CHIP_ENABLE, HIGH);
digitalWrite(WRITE_ENABLE, HIGH);
}
void write(int address, int byte) {
write_prepare();
write_byte(address, byte);
digitalWrite(CHIP_ENABLE, LOW);
}
void disable_software_protection() {
write_prepare();
write_byte(0x5555, 0xAA);
write_byte(0x2AAA, 0x55);
write_byte(0x5555, 0x80);
write_byte(0x5555, 0xAA);
write_byte(0x2AAA, 0x55);
write_byte(0x5555, 0x20);
delay(15); //wait for write cycle time (tWC)
digitalWrite(CHIP_ENABLE, LOW);
}
void setup() {
pinMode(SHIFT_DATA, OUTPUT);
pinMode(SHIFT_CLOCK, OUTPUT);
pinMode(SHIFT_LATCH, OUTPUT);
pinMode(WRITE_ENABLE, OUTPUT);
pinMode(CHIP_ENABLE, OUTPUT);
pinMode(OUTPUT_ENABLE, OUTPUT);
digitalWrite(CHIP_ENABLE, LOW);
Serial.begin(9600);
disable_software_protection();
write(0x4444, 0x55);
}
void loop() {
Serial.println(read(0x4444));
}