1.1 --- a/ArduinoAm29F010.cpp Sun Aug 09 01:10:40 2015 +0200
1.2 +++ b/ArduinoAm29F010.cpp Sun Aug 09 19:08:15 2015 +0200
1.3 @@ -16,7 +16,7 @@
1.4 with this program. If not, see <http://www.gnu.org/licenses/>.
1.5 */
1.6
1.7 -const int CE = A5, OE = A4, WE = A3,
1.8 +const int CE = A5, OE = A4, WE = A3, A16 = A2,
1.9 CS1 = 2, CS2 = 3,
1.10 DQ0 = 7, DQ1 = 6, DQ2 = 5, DQ3 = 4,
1.11 DQ4 = 8, DQ5 = 9, DQ6 = 10, DQ7 = 11;
1.12 @@ -111,6 +111,15 @@
1.13
1.14 void setAddress(int high, int low)
1.15 {
1.16 + /* The top bit is sent directly. */
1.17 +
1.18 + if (high & 0x100)
1.19 + digitalWrite(A16, HIGH);
1.20 + else
1.21 + digitalWrite(A16, LOW);
1.22 +
1.23 + /* The lower 16 bits are sent via the latches. */
1.24 +
1.25 writeData(high);
1.26 delayMicroseconds(1);
1.27 digitalWrite(CS2, HIGH);
1.28 @@ -153,21 +162,37 @@
1.29
1.30 int readCommand(const char buffer[])
1.31 {
1.32 - int high, low;
1.33 + int high, low, i;
1.34
1.35 - high = (fromHex(buffer[1]) << 4) + (fromHex(buffer[2]));
1.36 - low = (fromHex(buffer[3]) << 4) + (fromHex(buffer[4]));
1.37 + if (nread > 5)
1.38 + {
1.39 + high = fromHex(buffer[1]) << 8;
1.40 + i = 2;
1.41 + }
1.42 + else
1.43 + i = 1;
1.44 +
1.45 + high |= (fromHex(buffer[i]) << 4) + (fromHex(buffer[i+1]));
1.46 + low = (fromHex(buffer[i+2]) << 4) + (fromHex(buffer[i+3]));
1.47
1.48 return readOp(high, low);
1.49 }
1.50
1.51 bool writeCommand(const char buffer[])
1.52 {
1.53 - int high, low, data;
1.54 + int high, low, data, i;
1.55
1.56 - high = (fromHex(buffer[1]) << 4) + (fromHex(buffer[2]));
1.57 - low = (fromHex(buffer[3]) << 4) + (fromHex(buffer[4]));
1.58 - data = (fromHex(buffer[5]) << 4) + (fromHex(buffer[6]));
1.59 + if (nread > 7)
1.60 + {
1.61 + high = fromHex(buffer[1]) << 8;
1.62 + i = 2;
1.63 + }
1.64 + else
1.65 + i = 1;
1.66 +
1.67 + high |= (fromHex(buffer[i]) << 4) + (fromHex(buffer[i+1]));
1.68 + low = (fromHex(buffer[i+2]) << 4) + (fromHex(buffer[i+3]));
1.69 + data = (fromHex(buffer[i+4]) << 4) + (fromHex(buffer[i+5]));
1.70
1.71 writeOp(high, low, data);
1.72
1.73 @@ -252,6 +277,7 @@
1.74 pinMode(CE, OUTPUT);
1.75 pinMode(OE, OUTPUT);
1.76 pinMode(WE, OUTPUT);
1.77 + pinMode(A16, OUTPUT);
1.78 pinMode(CS1, OUTPUT);
1.79 pinMode(CS2, OUTPUT);
1.80 setDataOut();
1.81 @@ -261,6 +287,7 @@
1.82 digitalWrite(CE, HIGH);
1.83 digitalWrite(OE, HIGH);
1.84 digitalWrite(WE, HIGH);
1.85 + digitalWrite(A16, LOW);
1.86
1.87 // Initial state for the latches.
1.88
2.1 --- a/README.txt Sun Aug 09 01:10:40 2015 +0200
2.2 +++ b/README.txt Sun Aug 09 19:08:15 2015 +0200
2.3 @@ -42,8 +42,13 @@
2.4
2.5 Issuing read commands permits the testing of addresses in the device:
2.6
2.7 -R0000 (reads from the first location, 0x0000, residing in sector 0)
2.8 -R7fff (reads from the final location, 0x7fff, residing in sector 3)
2.9 + location sector
2.10 +R0000 0x0000 0 (the first location in the device)
2.11 +R00000 0x0000 0 (all 17 address bits indicated)
2.12 +R7fff 0x7fff 1 (the final location in sector 1)
2.13 +R07fff 0x7fff 1 (all 17 address bits indicated)
2.14 +R10000 0x10000 4 (the first location in sector 4)
2.15 +R1ffff 0x1ffff 7 (the final location in the device)
2.16
2.17 Uploading and Testing Images
2.18 ----------------------------
2.19 @@ -78,11 +83,12 @@
2.20 -----------------
2.21
2.22 Each sector is 16 kilobytes long, which corresponds to a 14-bit address range
2.23 -(0x0000 to 0x3FFF). The Arduino interface described below supports 16-bit
2.24 -addressing (A0...A15), permitting access to four sectors (at 0x0000, 0x4000,
2.25 -0x8000 and 0xC000), leaving A16 grounded and thus not accessing the upper four
2.26 -sectors in the device. However, A16 could be connected to VCC to access the
2.27 -upper four sectors.
2.28 +(0x0000 to 0x3FFF). The Arduino interface described below supports 17-bit
2.29 +addressing (A0...A16), permitting access to eight sectors (at 0x0000, 0x4000,
2.30 +0x8000, 0xC000, 0x10000, 0x14000, 0x18000 and 0x1C000). The simple mapping from
2.31 +a ROM cartridge to the device leaves A16 grounded and thus unable to access the
2.32 +upper four sectors in the device. However, A16 could be connected to VCC to
2.33 +access the upper four sectors.
2.34
2.35 Device Compatibility
2.36 ====================
2.37 @@ -209,18 +215,18 @@
2.38 Arduino Interfacing
2.39 ===================
2.40
2.41 -Arduino can employ at most 14 digital pins, whereas the Am29F010B requires 17
2.42 -address pins, 8 data pins, plus 3 control pins to be utilised.
2.43 +Arduino can employ at most 14 digital pins (plus 5 switchable analogue pins),
2.44 +whereas the Am29F010B requires 17 address pins, 8 data pins, plus 3 control
2.45 +pins to be utilised.
2.46
2.47 One solution is to map the 3 control pins directly to the Arduino, then to
2.48 -channel address and data via 8 common pins to latches, and then employ the
2.49 -remaining pins to control the latches.
2.50 +channel address and data via 8 common pins to latches, and then employ two
2.51 +remaining pins to control the latches. When neither latch is selected, the
2.52 +data pins will be used to read or write data from the flash memory.
2.53
2.54 -Two pins can be used to select the latches, and when neither latch is
2.55 -selected, the data pins will be used to read or write data from the flash
2.56 -memory.
2.57 -
2.58 -As a result, only 13 pins are needed on the Arduino.
2.59 +In this scheme, A16 must be directly controlled by an additional pin, separate
2.60 +from the latch-based mechanism. As a result, only 14 pins are needed on the
2.61 +Arduino.
2.62
2.63 74HC273 Pinout
2.64 --------------
2.65 @@ -267,7 +273,7 @@
2.66 Q5 A13
2.67 Q6 A14
2.68 Q7 A15
2.69 -GND A16 (not used)
2.70 +A2 A16
2.71 5V MR# MR#
2.72 5V VCC VCC VCC
2.73 GND GND GND VSS
2.74 @@ -279,6 +285,7 @@
2.75 74HC273 #1 D[7...0] = A[7...0]
2.76 74HC273 #1 CP = 0; 74HC273 #2 CP = 1
2.77 74HC273 #2 D[7...0] = A[15...8]
2.78 +Am29F010 A16 = A[16]
2.79
2.80 Write Data
2.81 ----------