# HG changeset patch # User Paul Boddie # Date 1439140095 -7200 # Node ID deaef57647e7da71a0764668193ed49bc1519d6e # Parent dcd08661531d719417358650109c9b3bfa6202eb Added support for controlling A16 when programming. Fixed the read examples. diff -r dcd08661531d -r deaef57647e7 ArduinoAm29F010.cpp --- a/ArduinoAm29F010.cpp Sun Aug 09 01:10:40 2015 +0200 +++ b/ArduinoAm29F010.cpp Sun Aug 09 19:08:15 2015 +0200 @@ -16,7 +16,7 @@ with this program. If not, see . */ -const int CE = A5, OE = A4, WE = A3, +const int CE = A5, OE = A4, WE = A3, A16 = A2, CS1 = 2, CS2 = 3, DQ0 = 7, DQ1 = 6, DQ2 = 5, DQ3 = 4, DQ4 = 8, DQ5 = 9, DQ6 = 10, DQ7 = 11; @@ -111,6 +111,15 @@ 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 latches. */ + writeData(high); delayMicroseconds(1); digitalWrite(CS2, HIGH); @@ -153,21 +162,37 @@ int readCommand(const char buffer[]) { - int high, low; + int high, low, i; - high = (fromHex(buffer[1]) << 4) + (fromHex(buffer[2])); - low = (fromHex(buffer[3]) << 4) + (fromHex(buffer[4])); + if (nread > 5) + { + high = fromHex(buffer[1]) << 8; + i = 2; + } + else + i = 1; + + high |= (fromHex(buffer[i]) << 4) + (fromHex(buffer[i+1])); + low = (fromHex(buffer[i+2]) << 4) + (fromHex(buffer[i+3])); return readOp(high, low); } bool writeCommand(const char buffer[]) { - int high, low, data; + int high, low, data, i; - high = (fromHex(buffer[1]) << 4) + (fromHex(buffer[2])); - low = (fromHex(buffer[3]) << 4) + (fromHex(buffer[4])); - data = (fromHex(buffer[5]) << 4) + (fromHex(buffer[6])); + if (nread > 7) + { + high = fromHex(buffer[1]) << 8; + i = 2; + } + else + i = 1; + + high |= (fromHex(buffer[i]) << 4) + (fromHex(buffer[i+1])); + low = (fromHex(buffer[i+2]) << 4) + (fromHex(buffer[i+3])); + data = (fromHex(buffer[i+4]) << 4) + (fromHex(buffer[i+5])); writeOp(high, low, data); @@ -252,6 +277,7 @@ pinMode(CE, OUTPUT); pinMode(OE, OUTPUT); pinMode(WE, OUTPUT); + pinMode(A16, OUTPUT); pinMode(CS1, OUTPUT); pinMode(CS2, OUTPUT); setDataOut(); @@ -261,6 +287,7 @@ digitalWrite(CE, HIGH); digitalWrite(OE, HIGH); digitalWrite(WE, HIGH); + digitalWrite(A16, LOW); // Initial state for the latches. diff -r dcd08661531d -r deaef57647e7 README.txt --- a/README.txt Sun Aug 09 01:10:40 2015 +0200 +++ b/README.txt Sun Aug 09 19:08:15 2015 +0200 @@ -42,8 +42,13 @@ Issuing read commands permits the testing of addresses in the device: -R0000 (reads from the first location, 0x0000, residing in sector 0) -R7fff (reads from the final location, 0x7fff, residing in sector 3) + location sector +R0000 0x0000 0 (the first location in the device) +R00000 0x0000 0 (all 17 address bits indicated) +R7fff 0x7fff 1 (the final location in sector 1) +R07fff 0x7fff 1 (all 17 address bits indicated) +R10000 0x10000 4 (the first location in sector 4) +R1ffff 0x1ffff 7 (the final location in the device) Uploading and Testing Images ---------------------------- @@ -78,11 +83,12 @@ ----------------- Each sector is 16 kilobytes long, which corresponds to a 14-bit address range -(0x0000 to 0x3FFF). The Arduino interface described below supports 16-bit -addressing (A0...A15), permitting access to four sectors (at 0x0000, 0x4000, -0x8000 and 0xC000), leaving A16 grounded and thus not accessing the upper four -sectors in the device. However, A16 could be connected to VCC to access the -upper four sectors. +(0x0000 to 0x3FFF). The Arduino interface described below supports 17-bit +addressing (A0...A16), permitting access to eight sectors (at 0x0000, 0x4000, +0x8000, 0xC000, 0x10000, 0x14000, 0x18000 and 0x1C000). The simple mapping from +a ROM cartridge to the device leaves A16 grounded and thus unable to access the +upper four sectors in the device. However, A16 could be connected to VCC to +access the upper four sectors. Device Compatibility ==================== @@ -209,18 +215,18 @@ Arduino Interfacing =================== -Arduino can employ at most 14 digital pins, whereas the Am29F010B requires 17 -address pins, 8 data pins, plus 3 control pins to be utilised. +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. 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 the -remaining pins to control the latches. +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. -Two pins can be used to select the latches, and when neither latch is -selected, the data pins will be used to read or write data from the flash -memory. - -As a result, only 13 pins are needed on the Arduino. +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 +Arduino. 74HC273 Pinout -------------- @@ -267,7 +273,7 @@ Q5 A13 Q6 A14 Q7 A15 -GND A16 (not used) +A2 A16 5V MR# MR# 5V VCC VCC VCC GND GND GND VSS @@ -279,6 +285,7 @@ 74HC273 #1 D[7...0] = A[7...0] 74HC273 #1 CP = 0; 74HC273 #2 CP = 1 74HC273 #2 D[7...0] = A[15...8] +Am29F010 A16 = A[16] Write Data ----------