From eed427f986f61b44fc0349a9ddd664b0d110abda Mon Sep 17 00:00:00 2001 From: AYM1607 Date: Sat, 12 Dec 2020 12:43:32 -0600 Subject: [PATCH] First working version of the programmer. Tested with a real AT28C256 EEPROM --- .../arduino_programmer/arduino_programmer.ino | 63 +++++++++++++++++-- .../arduino_tester/arduino_tester.ino | 29 +++++++-- serial_monitor/requirements.txt | 16 +++++ 3 files changed, 99 insertions(+), 9 deletions(-) create mode 100644 serial_monitor/requirements.txt diff --git a/arduino_programs/arduino_programmer/arduino_programmer.ino b/arduino_programs/arduino_programmer/arduino_programmer.ino index 8145200..effcf60 100644 --- a/arduino_programs/arduino_programmer/arduino_programmer.ino +++ b/arduino_programs/arduino_programmer/arduino_programmer.ino @@ -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() { diff --git a/arduino_programs/arduino_tester/arduino_tester.ino b/arduino_programs/arduino_tester/arduino_tester.ino index fea70bb..ffd829a 100644 --- a/arduino_programs/arduino_tester/arduino_tester.ino +++ b/arduino_programs/arduino_tester/arduino_tester.ino @@ -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(); } diff --git a/serial_monitor/requirements.txt b/serial_monitor/requirements.txt new file mode 100644 index 0000000..f7507fa --- /dev/null +++ b/serial_monitor/requirements.txt @@ -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