ArduinoAm29F010

Changeset

7:93d3bc9658c7
2015-01-19 Paul Boddie raw files shortlog changelog graph Fixed command delivery for erase and program operations. Simplified the completion detection code, using plain read operations. Reduced various delays.
ArduinoAm29F010.cpp (file)
     1.1 --- a/ArduinoAm29F010.cpp	Mon Jan 19 20:43:36 2015 +0100
     1.2 +++ b/ArduinoAm29F010.cpp	Mon Jan 19 23:12:12 2015 +0100
     1.3 @@ -6,9 +6,12 @@
     1.4  const int BUFSIZE = 8;
     1.5  char inbuffer[BUFSIZE];
     1.6  
     1.7 -const char CHIP_ERASE[] = "W5555AA\nW2AAA55\nW555580\nW5555AA\nW2AAA55\nW555510\n";
     1.8 -const char SECTOR_ERASE[] = "W5555AA\nW2AAA55\nW555580\nW5555AA\nW2AAA55\n";
     1.9 -const char PROGRAM[] = "W5555AA\nW2AAA55\nW5555A0\n";
    1.10 +const char ERASE[][8] = {
    1.11 +    "W5555AA", "W2AAA55", "W555580", "W5555AA", "W2AAA55"
    1.12 +    };
    1.13 +const char PROGRAM[][8] = {
    1.14 +    "W5555AA", "W2AAA55", "W5555A0"
    1.15 +    };
    1.16  
    1.17  int fromHex(char c)
    1.18  {
    1.19 @@ -67,7 +70,7 @@
    1.20      int data = 0;
    1.21  
    1.22      setDataIn();
    1.23 -    delay(10);
    1.24 +    delay(1);
    1.25      data = sampleData();
    1.26      setDataOut();
    1.27      return data;
    1.28 @@ -107,10 +110,10 @@
    1.29  
    1.30      digitalWrite(CE, LOW);
    1.31      setAddress(high, low);
    1.32 -    delay(10);
    1.33 +    delay(1);
    1.34      digitalWrite(OE, LOW);
    1.35      data = readData();
    1.36 -    delay(10);
    1.37 +    delay(1);
    1.38      digitalWrite(OE, HIGH);
    1.39      digitalWrite(CE, HIGH);
    1.40  
    1.41 @@ -121,10 +124,10 @@
    1.42  {
    1.43      digitalWrite(CE, LOW);
    1.44      setAddress(high, low);
    1.45 -    delay(10);
    1.46 +    delay(1);
    1.47      digitalWrite(WE, LOW);
    1.48      writeData(data);
    1.49 -    delay(10);
    1.50 +    delay(1);
    1.51      digitalWrite(WE, HIGH);
    1.52      digitalWrite(CE, HIGH);
    1.53  }
    1.54 @@ -162,32 +165,25 @@
    1.55  {
    1.56      int data;
    1.57  
    1.58 -    setDataIn();
    1.59 -    digitalWrite(CE, LOW);
    1.60 -
    1.61      do
    1.62      {
    1.63          delay(10);
    1.64 -        digitalWrite(OE, LOW);
    1.65 -        delay(10);
    1.66 -        data = sampleData();
    1.67 -        delay(10);
    1.68 -        digitalWrite(OE, HIGH);
    1.69 -        Serial.println(data, BIN);
    1.70 +        data = readOp(high, low);
    1.71      } while (
    1.72          ((data & 0x80) != (written & 0x80)) &&
    1.73          ((data & 0x20) == 0)
    1.74          );
    1.75  
    1.76 -    digitalWrite(CE, HIGH);
    1.77 -    setDataOut();
    1.78 -
    1.79 -    return ((data & 0x20) == 0);
    1.80 +    return readOp(high, low) == written;
    1.81  }
    1.82  
    1.83  bool chipErase()
    1.84  {
    1.85 -    writeCommand(sizeof(CHIP_ERASE), CHIP_ERASE);
    1.86 +    for (int i = 0; i < 5; i++)
    1.87 +    {
    1.88 +        writeCommand(7, ERASE[i]);
    1.89 +    }
    1.90 +    writeOp(0x55, 0x55, 0x30);
    1.91      return waitForCompletion(0, 0, 0xff);
    1.92  }
    1.93  
    1.94 @@ -203,7 +199,10 @@
    1.95  
    1.96      high = (fromHex(buffer[1]) << 6) & 0xff;
    1.97  
    1.98 -    writeCommand(sizeof(SECTOR_ERASE), SECTOR_ERASE);
    1.99 +    for (int i = 0; i < 5; i++)
   1.100 +    {
   1.101 +        writeCommand(7, ERASE[i]);
   1.102 +    }
   1.103      writeOp(high, 0, 0x30);
   1.104  
   1.105      // Result of erase if 0xff written to all locations.
   1.106 @@ -225,7 +224,10 @@
   1.107      low = (fromHex(buffer[3]) << 4) + (fromHex(buffer[4]));
   1.108      data = (fromHex(buffer[5]) << 4) + (fromHex(buffer[6]));
   1.109  
   1.110 -    writeCommand(sizeof(PROGRAM), PROGRAM);
   1.111 +    for (int i = 0; i < 3; i++)
   1.112 +    {
   1.113 +        writeCommand(7, PROGRAM[i]);
   1.114 +    }
   1.115      writeOp(high, low, data);
   1.116  
   1.117      return waitForCompletion(high, low, data);