# HG changeset patch # User Paul Boddie # Date 1421705532 -3600 # Node ID 93d3bc9658c7d72c8403e3380411b1883756c3cd # Parent 22970a6cd9810edbf47fc75d4396293d7b628e8c Fixed command delivery for erase and program operations. Simplified the completion detection code, using plain read operations. Reduced various delays. diff -r 22970a6cd981 -r 93d3bc9658c7 ArduinoAm29F010.cpp --- a/ArduinoAm29F010.cpp Mon Jan 19 20:43:36 2015 +0100 +++ b/ArduinoAm29F010.cpp Mon Jan 19 23:12:12 2015 +0100 @@ -6,9 +6,12 @@ const int BUFSIZE = 8; char inbuffer[BUFSIZE]; -const char CHIP_ERASE[] = "W5555AA\nW2AAA55\nW555580\nW5555AA\nW2AAA55\nW555510\n"; -const char SECTOR_ERASE[] = "W5555AA\nW2AAA55\nW555580\nW5555AA\nW2AAA55\n"; -const char PROGRAM[] = "W5555AA\nW2AAA55\nW5555A0\n"; +const char ERASE[][8] = { + "W5555AA", "W2AAA55", "W555580", "W5555AA", "W2AAA55" + }; +const char PROGRAM[][8] = { + "W5555AA", "W2AAA55", "W5555A0" + }; int fromHex(char c) { @@ -67,7 +70,7 @@ int data = 0; setDataIn(); - delay(10); + delay(1); data = sampleData(); setDataOut(); return data; @@ -107,10 +110,10 @@ digitalWrite(CE, LOW); setAddress(high, low); - delay(10); + delay(1); digitalWrite(OE, LOW); data = readData(); - delay(10); + delay(1); digitalWrite(OE, HIGH); digitalWrite(CE, HIGH); @@ -121,10 +124,10 @@ { digitalWrite(CE, LOW); setAddress(high, low); - delay(10); + delay(1); digitalWrite(WE, LOW); writeData(data); - delay(10); + delay(1); digitalWrite(WE, HIGH); digitalWrite(CE, HIGH); } @@ -162,32 +165,25 @@ { int data; - setDataIn(); - digitalWrite(CE, LOW); - do { delay(10); - digitalWrite(OE, LOW); - delay(10); - data = sampleData(); - delay(10); - digitalWrite(OE, HIGH); - Serial.println(data, BIN); + data = readOp(high, low); } while ( ((data & 0x80) != (written & 0x80)) && ((data & 0x20) == 0) ); - digitalWrite(CE, HIGH); - setDataOut(); - - return ((data & 0x20) == 0); + return readOp(high, low) == written; } bool chipErase() { - writeCommand(sizeof(CHIP_ERASE), CHIP_ERASE); + for (int i = 0; i < 5; i++) + { + writeCommand(7, ERASE[i]); + } + writeOp(0x55, 0x55, 0x30); return waitForCompletion(0, 0, 0xff); } @@ -203,7 +199,10 @@ high = (fromHex(buffer[1]) << 6) & 0xff; - writeCommand(sizeof(SECTOR_ERASE), SECTOR_ERASE); + for (int i = 0; i < 5; i++) + { + writeCommand(7, ERASE[i]); + } writeOp(high, 0, 0x30); // Result of erase if 0xff written to all locations. @@ -225,7 +224,10 @@ low = (fromHex(buffer[3]) << 4) + (fromHex(buffer[4])); data = (fromHex(buffer[5]) << 4) + (fromHex(buffer[6])); - writeCommand(sizeof(PROGRAM), PROGRAM); + for (int i = 0; i < 3; i++) + { + writeCommand(7, PROGRAM[i]); + } writeOp(high, low, data); return waitForCompletion(high, low, data);