# HG changeset patch # User Paul Boddie # Date 1474929393 -7200 # Node ID c4a05ef934c8a2fa178b00fff3e7f508cc0e7b86 # Parent ca010cf91fddfc3755d27460de474b1054d778f2 Added support for using shift registers instead of flip-flops. diff -r ca010cf91fdd -r c4a05ef934c8 ArduinoAm29F010.cpp --- a/ArduinoAm29F010.cpp Sat Aug 29 18:00:34 2015 +0200 +++ b/ArduinoAm29F010.cpp Tue Sep 27 00:36:33 2016 +0200 @@ -1,7 +1,7 @@ /* Interfacing the Arduino Duemilanove to Am29F010 devices. -Copyright (C) 2015 Paul Boddie +Copyright (C) 2015, 2016 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -17,7 +17,13 @@ */ const int CE = A5, OE = A4, WE = A3, A16 = A2, - CS1 = 2, CS2 = 3, +#ifdef CIRCUIT_74HC273 + CS1 = 2, CS2 = 3, /* using 74HC273 */ +#endif +#ifdef CIRCUIT_74HC595 + SHIFT_SCK = 2, SHIFT_RCK = 3, /* using 74HC595 */ + SHIFT_SI = 12, +#endif DQ0 = 7, DQ1 = 6, DQ2 = 5, DQ3 = 4, DQ4 = 8, DQ5 = 9, DQ6 = 10, DQ7 = 11; @@ -109,6 +115,7 @@ } } +#ifdef CIRCUIT_74HC273 void setAddress(int high, int low) { /* The top bit is sent directly. */ @@ -131,6 +138,51 @@ delayMicroseconds(1); digitalWrite(CS1, LOW); } +#endif + +#ifdef CIRCUIT_74HC595 +void writeAddress(int v) +{ + int mask; + + for (mask = 0x80; mask; mask >>= 1) + { + if (v & mask) + { + digitalWrite(SHIFT_SI, HIGH); + } + else + { + digitalWrite(SHIFT_SI, LOW); + } + + delayMicroseconds(1); + digitalWrite(SHIFT_SCK, HIGH); + delayMicroseconds(1); + digitalWrite(SHIFT_SCK, LOW); + } + + delayMicroseconds(1); + digitalWrite(SHIFT_RCK, HIGH); + delayMicroseconds(1); + digitalWrite(SHIFT_RCK, LOW); +} + +void setAddress(int high, int low) +{ + /* The top bit is sent directly. */ + + if (high & 0x100) + digitalWrite(A16, HIGH); + else + digitalWrite(A16, LOW); + + /* The lower 16 bits are sent via the shift registers. */ + + writeAddress(high); + writeAddress(low); +} +#endif int readOp(int high, int low) { @@ -282,8 +334,18 @@ pinMode(OE, OUTPUT); pinMode(WE, OUTPUT); pinMode(A16, OUTPUT); + +#ifdef CIRCUIT_74HC273 pinMode(CS1, OUTPUT); pinMode(CS2, OUTPUT); +#endif + +#ifdef CIRCUIT_74HC595 + pinMode(SHIFT_SCK, OUTPUT); + pinMode(SHIFT_RCK, OUTPUT); + pinMode(SHIFT_SI, OUTPUT); +#endif + setDataOut(); // Initial state for the flash device. @@ -295,8 +357,15 @@ // Initial state for the latches. +#ifdef CIRCUIT_74HC273 digitalWrite(CS1, LOW); digitalWrite(CS2, LOW); +#endif + +#ifdef CIRCUIT_74HC595 + digitalWrite(SHIFT_SCK, LOW); + digitalWrite(SHIFT_RCK, LOW); +#endif // Interface loop. diff -r ca010cf91fdd -r c4a05ef934c8 Makefile --- a/Makefile Sat Aug 29 18:00:34 2015 +0200 +++ b/Makefile Tue Sep 27 00:36:33 2016 +0200 @@ -11,9 +11,12 @@ EXTRA_CINCS = EXTRA_CXXINCS = +CIRCUIT = 74HC273 +#CIRCUIT = 74HC595 ### Internal definitions. +CIRCUIT_DEFS = -DCIRCUIT_$(CIRCUIT) ARDUINO = $(INSTALL_DIR)/hardware/arduino/cores/arduino VARIANT = $(INSTALL_DIR)/hardware/arduino/variants/standard @@ -33,8 +36,8 @@ DEBUG = stabs # Place -D or -U options here -CDEFS = -DF_CPU=$(F_CPU) -CXXDEFS = -DF_CPU=$(F_CPU) +CDEFS = -DF_CPU=$(F_CPU) $(CIRCUIT_DEFS) +CXXDEFS = -DF_CPU=$(F_CPU) $(CIRCUIT_DEFS) # Place -I options here CINCS = -I$(ARDUINO) -I$(VARIANT) $(EXTRA_CINCS) diff -r ca010cf91fdd -r c4a05ef934c8 README.txt --- a/README.txt Sat Aug 29 18:00:34 2015 +0200 +++ b/README.txt Tue Sep 27 00:36:33 2016 +0200 @@ -51,6 +51,23 @@ sudo make upload +Configuring the Software +------------------------ + +By default, the software is configured for a circuit using 74HC273 flip-flop +integrated circuits. In the Makefile, the CIRCUIT variable is set as follows: + +CIRCUIT = 74HC273 + +To change this to support 74HC595 shift register integrated circuits, the +variable is set as follows: + +CIRCUIT = 74HC595 + +Clean the generated files and run make again after reconfiguring: + +make clean && make + Testing the Program ------------------- @@ -270,12 +287,17 @@ Arduino can employ at most 14 digital pins (plus 5 switchable analogue pins), whereas the Am29F010B requires 17 address pins, 8 data pins, plus 3 control -pins to be utilised. +pins to be utilised. (Note that digital pin 13 also drives an LED and pins 0 +and 1 are unavailable if the serial interface is being used.) + +Using 74HC273 Flip-Flops +------------------------ One solution is to map the 3 control pins directly to the Arduino, then to -channel address and data via 8 common pins to latches, and then employ two -remaining pins to control the latches. When neither latch is selected, the -data pins will be used to read or write data from the flash memory. +channel addresses and data via 8 common pins, with addresses being stored in +latches or flip-flops, and then to employ two remaining pins to control the +latches. When neither latch is selected, the data pins will be used to read or +write data from the flash memory. In this scheme, A16 must be directly controlled by an additional pin, separate from the latch-based mechanism. As a result, only 14 pins are needed on the @@ -358,6 +380,68 @@ Q[7...0] = 74HC273 #0 Q[7...0] OE# = 1 +Using 74HC595 Shift Registers +----------------------------- + +Another solution is to map the 3 control pins directly to the Arduino, then to +channel addresses via a single pin to a pair of shift registers, and then +employ two remaining pins to control the shift registers. Eight separate data +pins will be used to read or write data from the flash memory. + +In this scheme, A16 must be directly controlled by an additional pin, separate +from the shift-register-based mechanism. As a result, only 15 pins are needed +on the Arduino. + +74HC595 Pinout +-------------- + +QB 1 \/ 16 VCC +QC 2 15 QA +QD 3 14 SI +QE 4 13 G# +QF 5 12 RCK +QG 6 11 SCK +QH 7 10 SCLR# +GND 8 9 QH' + +Arduino 74HC595#1 74HC595#2 Am29F010 +------- --------- --------- -------- +A5 CE# +A4 OE# +A3 WE# +2 SCK SCK +3 RCK RCK +4 DQ3 +5 DQ2 +6 DQ1 +7 DQ0 +8 DQ4 +9 DQ5 +10 DQ6 +11 DQ7 +12 SI + QA A0 + QB A1 + QC A2 + QD A3 + QE A4 + QF A5 + QG A6 + QH A7 + QA A8 + QB A9 + QC A10 + QD A11 + QE A12 + QF A13 + QG A14 + QH A15 +A2 A16 +5V SCLR# SCLR# +5V VCC VCC VCC +GND G# G# +GND GND GND VSS + Pins ==== diff -r ca010cf91fdd -r c4a05ef934c8 docs/COPYING.txt --- a/docs/COPYING.txt Sat Aug 29 18:00:34 2015 +0200 +++ b/docs/COPYING.txt Tue Sep 27 00:36:33 2016 +0200 @@ -4,7 +4,7 @@ The following terms apply to the software, documentation and circuit designs provided by this project: -Copyright (C) 2015 Paul Boddie +Copyright (C) 2015, 2016 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software