First working version of the programmer. Tested with a real AT28C256 EEPROM
This commit is contained in:
parent
9af30ef829
commit
eed427f986
3 changed files with 99 additions and 9 deletions
|
|
@ -27,6 +27,7 @@ void latchOutput() {
|
|||
PORTD |= latchMask;
|
||||
delayMicroseconds(1);
|
||||
PORTD &= ~latchMask;
|
||||
delayMicroseconds(1);
|
||||
}
|
||||
|
||||
void commitWrite() {
|
||||
|
|
@ -88,6 +89,7 @@ void setAddress(int address, bool outputEnable) {
|
|||
}
|
||||
|
||||
byte readEEPROM(int address) {
|
||||
byte result = 0;
|
||||
// TODO: Think about adding a delay if the last operation was a write and where it is appropriate to put it.
|
||||
// If the last operation wasn't a read we need to set our pins as input.
|
||||
if (lastOp != LAST_OP_READ) {
|
||||
|
|
@ -97,7 +99,18 @@ byte readEEPROM(int address) {
|
|||
// In contrast with the write function, it's okay to set output enable after setting the
|
||||
// pins as inputs. This way, the arduino pins are already ready to sink current when the
|
||||
// EEPROM starts driving the bus.
|
||||
byte result = (PINB << 3) | (PIND >> 5) ;
|
||||
setAddress(address, true);
|
||||
// For some reason, PINB takes a long time to update, a delay of a minimum of 2 microsends
|
||||
// Must be added. The datasheet of the AT28C256 specifies a time from address to output of 150ns max
|
||||
// and a time from output enabled to output of 70ns max, thus it makes no sense to wait 2000ns, but
|
||||
// if it is not done, the most significant nibble is always 0xF.
|
||||
delayMicroseconds(2);
|
||||
result = (PINB << 3) | (PIND >> 5);
|
||||
|
||||
//for (int pin = EEPROM_D7; pin >= EEPROM_D0; pin--) {
|
||||
// result <<= 1;
|
||||
// result += digitalRead(pin);
|
||||
//}
|
||||
|
||||
lastOp = LAST_OP_READ;
|
||||
return result;
|
||||
|
|
@ -122,9 +135,14 @@ void writeEEPROM(int address, byte data, bool cooldown) {
|
|||
|
||||
// EEPROM_D0 to D2 correspond to PD5 to PD7
|
||||
// EEPROM_D3 to D7 correspond to PB0 to PB4
|
||||
PORTD &= (data << 5) & 0b00011111;
|
||||
PORTB &= (data >> 3) & 0b11100000;
|
||||
PORTD = (PORTD & 0b00011111 ) | (data << 5);
|
||||
PORTB = (PORTB & 0b11100000) | (data >> 3) ;
|
||||
|
||||
// Slow version.
|
||||
//for (int pin = EEPROM_D0; pin < EEPROM_D7; pin++, data >>= 1) {
|
||||
// digitalWrite(pin, data & 1);
|
||||
//}
|
||||
|
||||
commitWrite();
|
||||
lastOp = LAST_OP_WRITE;
|
||||
|
||||
|
|
@ -134,6 +152,40 @@ void writeEEPROM(int address, byte data, bool cooldown) {
|
|||
}
|
||||
|
||||
|
||||
void disableSoftwareProtection() {
|
||||
|
||||
writeEEPROM(0x5555, 0xAA, false);
|
||||
writeEEPROM(0x2AAA, 0x55, false);
|
||||
writeEEPROM(0x5555, 0x80, false);
|
||||
writeEEPROM(0x5555, 0xAA, false);
|
||||
writeEEPROM(0x2AAA, 0x55, false);
|
||||
writeEEPROM(0x5555, 0x20, false);
|
||||
|
||||
delay(10);
|
||||
}
|
||||
|
||||
void dumpFirts256Bytes() {
|
||||
byte data;
|
||||
Serial.println("Reading EEPROM");
|
||||
for (int addr = 0; addr < 256; addr++) {
|
||||
data = readEEPROM(addr);
|
||||
sprintf(printBuff, "Address: %x data: 0b", addr);
|
||||
Serial.print(printBuff);
|
||||
for (int i = 0; i < 8; i++, data <<= 1) {
|
||||
Serial.print((data & 0x80) >> 7);
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
|
||||
void writeFirst256Bytes() {
|
||||
Serial.println("Writing EEPROM");
|
||||
for (int addr = 0; addr < 256; addr++) {
|
||||
writeEEPROM(addr, addr, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
pinMode(SHIFT_DATA, OUTPUT);
|
||||
|
|
@ -148,8 +200,9 @@ void setup() {
|
|||
|
||||
Serial.begin(115200);
|
||||
|
||||
writeEEPROM(0x1234, 0x55, true);
|
||||
writeEEPROM(0x4321, 0x7E, true);
|
||||
dumpFirts256Bytes();
|
||||
//writeFirst256Bytes();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,21 @@
|
|||
#define ADDRESS_CLOCK 18
|
||||
#define WRITE_CLOCK 19
|
||||
|
||||
/*
|
||||
|
||||
PORT mappings for data pins:
|
||||
|
||||
2 PORTE 4
|
||||
3 PORTE 5
|
||||
4 PORTG 5
|
||||
5 PORTE 3
|
||||
6 PORTH 3
|
||||
7 PORTH 4
|
||||
8 PORTH 5
|
||||
9 PORTH 6
|
||||
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
attachInterrupt(digitalPinToInterrupt(ADDRESS_CLOCK), onAddressClock, RISING);
|
||||
|
|
@ -27,10 +42,16 @@ void onAddressClock() {
|
|||
}
|
||||
|
||||
void onWriteClock() {
|
||||
Serial.print("Data: 0b");
|
||||
for (int pin = DATA_7; pin >= DATA_0; pin--) {
|
||||
Serial.print(digitalRead(pin));
|
||||
}
|
||||
Serial.print("Data: 0b");
|
||||
// TODO: Find a way of making this more readable.
|
||||
Serial.print((PINH & 0x40) >> 6);
|
||||
Serial.print((PINH & 0x20) >> 5);
|
||||
Serial.print((PINH & 0x10) >> 4);
|
||||
Serial.print((PINH & 0x08) >> 3);
|
||||
Serial.print((PINE & 0x08) >> 3);
|
||||
Serial.print((PING & 0x20) >> 5);
|
||||
Serial.print((PINE & 0x20) >> 5);
|
||||
Serial.print((PINE & 0x10) >> 4);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
|
|
|||
16
serial_monitor/requirements.txt
Normal file
16
serial_monitor/requirements.txt
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
appdirs==1.4.4
|
||||
astroid==2.4.2
|
||||
isort==5.6.4
|
||||
jedi==0.17.2
|
||||
lazy-object-proxy==1.4.3
|
||||
mccabe==0.6.1
|
||||
mypy-extensions==0.4.3
|
||||
parso==0.7.1
|
||||
pathspec==0.8.1
|
||||
pylint==2.6.0
|
||||
pyserial==3.5
|
||||
rope==0.18.0
|
||||
six==1.15.0
|
||||
toml==0.10.2
|
||||
typing-extensions==3.7.4.3
|
||||
wrapt==1.12.1
|
||||
Loading…
Add table
Add a link
Reference in a new issue