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