ArduinoAm29F010

Changeset

31:cb9fe339c6ed
2015-08-23 Paul Boddie raw files shortlog changelog graph Fixed data pin I/O which made assumptions about pin ordering.
ArduinoAm29F010.cpp (file)
     1.1 --- a/ArduinoAm29F010.cpp	Sun Aug 23 19:20:03 2015 +0200
     1.2 +++ b/ArduinoAm29F010.cpp	Sun Aug 23 20:02:09 2015 +0200
     1.3 @@ -21,6 +21,7 @@
     1.4            DQ0 = 7, DQ1 = 6, DQ2 = 5, DQ3 = 4,
     1.5            DQ4 = 8, DQ5 = 9, DQ6 = 10, DQ7 = 11;
     1.6  
     1.7 +const int datapins[8] = {DQ7, DQ6, DQ5, DQ4, DQ3, DQ2, DQ1, DQ0};
     1.8  const int BUFSIZE = 9;
     1.9  char inbuffer[BUFSIZE];
    1.10  int nread = 0;
    1.11 @@ -69,16 +70,14 @@
    1.12  
    1.13  int sampleData()
    1.14  {
    1.15 -    int i = DQ7;
    1.16 +    int i = 0; /* start at DQ7 */
    1.17      int data = 0;
    1.18  
    1.19 -    while (1)
    1.20 +    while (i < 8)
    1.21      {
    1.22 -        data += digitalRead(i);
    1.23 -        if (i == DQ0)
    1.24 -            break;
    1.25 -        i--;
    1.26          data <<= 1;
    1.27 +        data += digitalRead(datapins[i]);
    1.28 +        i++;
    1.29      }
    1.30  
    1.31      return data;
    1.32 @@ -97,14 +96,12 @@
    1.33  
    1.34  void writeData(int data)
    1.35  {
    1.36 -    int i = DQ0;
    1.37 +    int i = 8; /* start at DQ0 */
    1.38  
    1.39 -    while (1)
    1.40 +    while (i > 0)
    1.41      {
    1.42 -        digitalWrite(i, data % 2);
    1.43 -        if (i == DQ7)
    1.44 -            break;
    1.45 -        i++;
    1.46 +	i--;
    1.47 +        digitalWrite(datapins[i], data % 2);
    1.48          data >>= 1;
    1.49      }
    1.50  }