ArduinoAm29F010

Changeset

38:c4a05ef934c8
2016-09-27 Paul Boddie raw files shortlog changelog graph Added support for using shift registers instead of flip-flops.
ArduinoAm29F010.cpp (file) Makefile (file) README.txt (file) docs/COPYING.txt (file)
     1.1 --- a/ArduinoAm29F010.cpp	Sat Aug 29 18:00:34 2015 +0200
     1.2 +++ b/ArduinoAm29F010.cpp	Tue Sep 27 00:36:33 2016 +0200
     1.3 @@ -1,7 +1,7 @@
     1.4  /*
     1.5  Interfacing the Arduino Duemilanove to Am29F010 devices.
     1.6  
     1.7 -Copyright (C) 2015 Paul Boddie <paul@boddie.org.uk>
     1.8 +Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>
     1.9  
    1.10  This program is free software; you can redistribute it and/or modify it under
    1.11  the terms of the GNU General Public License as published by the Free Software
    1.12 @@ -17,7 +17,13 @@
    1.13  */
    1.14  
    1.15  const int CE = A5, OE = A4, WE = A3, A16 = A2,
    1.16 -          CS1 = 2, CS2 = 3,
    1.17 +#ifdef CIRCUIT_74HC273
    1.18 +          CS1 = 2, CS2 = 3,                     /* using 74HC273 */
    1.19 +#endif
    1.20 +#ifdef CIRCUIT_74HC595
    1.21 +          SHIFT_SCK = 2, SHIFT_RCK = 3,         /* using 74HC595 */
    1.22 +          SHIFT_SI = 12,
    1.23 +#endif
    1.24            DQ0 = 7, DQ1 = 6, DQ2 = 5, DQ3 = 4,
    1.25            DQ4 = 8, DQ5 = 9, DQ6 = 10, DQ7 = 11;
    1.26  
    1.27 @@ -109,6 +115,7 @@
    1.28      }
    1.29  }
    1.30  
    1.31 +#ifdef CIRCUIT_74HC273
    1.32  void setAddress(int high, int low)
    1.33  {
    1.34      /* The top bit is sent directly. */
    1.35 @@ -131,6 +138,51 @@
    1.36      delayMicroseconds(1);
    1.37      digitalWrite(CS1, LOW);
    1.38  }
    1.39 +#endif
    1.40 +
    1.41 +#ifdef CIRCUIT_74HC595
    1.42 +void writeAddress(int v)
    1.43 +{
    1.44 +    int mask;
    1.45 +
    1.46 +    for (mask = 0x80; mask; mask >>= 1)
    1.47 +    {
    1.48 +        if (v & mask)
    1.49 +        {
    1.50 +            digitalWrite(SHIFT_SI, HIGH);
    1.51 +        }
    1.52 +        else
    1.53 +        {
    1.54 +            digitalWrite(SHIFT_SI, LOW);
    1.55 +        }
    1.56 +
    1.57 +        delayMicroseconds(1);
    1.58 +        digitalWrite(SHIFT_SCK, HIGH);
    1.59 +        delayMicroseconds(1);
    1.60 +        digitalWrite(SHIFT_SCK, LOW);
    1.61 +    }
    1.62 +
    1.63 +    delayMicroseconds(1);
    1.64 +    digitalWrite(SHIFT_RCK, HIGH);
    1.65 +    delayMicroseconds(1);
    1.66 +    digitalWrite(SHIFT_RCK, LOW);
    1.67 +}
    1.68 +
    1.69 +void setAddress(int high, int low)
    1.70 +{
    1.71 +    /* The top bit is sent directly. */
    1.72 +
    1.73 +    if (high & 0x100)
    1.74 +        digitalWrite(A16, HIGH);
    1.75 +    else
    1.76 +        digitalWrite(A16, LOW);
    1.77 +
    1.78 +    /* The lower 16 bits are sent via the shift registers. */
    1.79 +
    1.80 +    writeAddress(high);
    1.81 +    writeAddress(low);
    1.82 +}
    1.83 +#endif
    1.84  
    1.85  int readOp(int high, int low)
    1.86  {
    1.87 @@ -282,8 +334,18 @@
    1.88      pinMode(OE, OUTPUT);
    1.89      pinMode(WE, OUTPUT);
    1.90      pinMode(A16, OUTPUT);
    1.91 +
    1.92 +#ifdef CIRCUIT_74HC273
    1.93      pinMode(CS1, OUTPUT);
    1.94      pinMode(CS2, OUTPUT);
    1.95 +#endif
    1.96 +
    1.97 +#ifdef CIRCUIT_74HC595
    1.98 +    pinMode(SHIFT_SCK, OUTPUT);
    1.99 +    pinMode(SHIFT_RCK, OUTPUT);
   1.100 +    pinMode(SHIFT_SI, OUTPUT);
   1.101 +#endif
   1.102 +
   1.103      setDataOut();
   1.104  
   1.105      // Initial state for the flash device.
   1.106 @@ -295,8 +357,15 @@
   1.107  
   1.108      // Initial state for the latches.
   1.109  
   1.110 +#ifdef CIRCUIT_74HC273
   1.111      digitalWrite(CS1, LOW);
   1.112      digitalWrite(CS2, LOW);
   1.113 +#endif
   1.114 +
   1.115 +#ifdef CIRCUIT_74HC595
   1.116 +    digitalWrite(SHIFT_SCK, LOW);
   1.117 +    digitalWrite(SHIFT_RCK, LOW);
   1.118 +#endif
   1.119  
   1.120      // Interface loop.
   1.121  
     2.1 --- a/Makefile	Sat Aug 29 18:00:34 2015 +0200
     2.2 +++ b/Makefile	Tue Sep 27 00:36:33 2016 +0200
     2.3 @@ -11,9 +11,12 @@
     2.4  EXTRA_CINCS =
     2.5  EXTRA_CXXINCS =
     2.6  
     2.7 +CIRCUIT = 74HC273
     2.8 +#CIRCUIT = 74HC595
     2.9  
    2.10  ### Internal definitions.
    2.11  
    2.12 +CIRCUIT_DEFS = -DCIRCUIT_$(CIRCUIT)
    2.13  
    2.14  ARDUINO = $(INSTALL_DIR)/hardware/arduino/cores/arduino
    2.15  VARIANT = $(INSTALL_DIR)/hardware/arduino/variants/standard
    2.16 @@ -33,8 +36,8 @@
    2.17  DEBUG = stabs
    2.18  
    2.19  # Place -D or -U options here
    2.20 -CDEFS = -DF_CPU=$(F_CPU)
    2.21 -CXXDEFS = -DF_CPU=$(F_CPU)
    2.22 +CDEFS = -DF_CPU=$(F_CPU) $(CIRCUIT_DEFS)
    2.23 +CXXDEFS = -DF_CPU=$(F_CPU) $(CIRCUIT_DEFS)
    2.24  
    2.25  # Place -I options here
    2.26  CINCS = -I$(ARDUINO) -I$(VARIANT) $(EXTRA_CINCS)
     3.1 --- a/README.txt	Sat Aug 29 18:00:34 2015 +0200
     3.2 +++ b/README.txt	Tue Sep 27 00:36:33 2016 +0200
     3.3 @@ -51,6 +51,23 @@
     3.4  
     3.5  sudo make upload
     3.6  
     3.7 +Configuring the Software
     3.8 +------------------------
     3.9 +
    3.10 +By default, the software is configured for a circuit using 74HC273 flip-flop
    3.11 +integrated circuits. In the Makefile, the CIRCUIT variable is set as follows:
    3.12 +
    3.13 +CIRCUIT = 74HC273
    3.14 +
    3.15 +To change this to support 74HC595 shift register integrated circuits, the
    3.16 +variable is set as follows:
    3.17 +
    3.18 +CIRCUIT = 74HC595
    3.19 +
    3.20 +Clean the generated files and run make again after reconfiguring:
    3.21 +
    3.22 +make clean && make
    3.23 +
    3.24  Testing the Program
    3.25  -------------------
    3.26  
    3.27 @@ -270,12 +287,17 @@
    3.28  
    3.29  Arduino can employ at most 14 digital pins (plus 5 switchable analogue pins),
    3.30  whereas the Am29F010B requires 17 address pins, 8 data pins, plus 3 control
    3.31 -pins to be utilised.
    3.32 +pins to be utilised. (Note that digital pin 13 also drives an LED and pins 0
    3.33 +and 1 are unavailable if the serial interface is being used.)
    3.34 +
    3.35 +Using 74HC273 Flip-Flops
    3.36 +------------------------
    3.37  
    3.38  One solution is to map the 3 control pins directly to the Arduino, then to
    3.39 -channel address and data via 8 common pins to latches, and then employ two
    3.40 -remaining pins to control the latches. When neither latch is selected, the
    3.41 -data pins will be used to read or write data from the flash memory.
    3.42 +channel addresses and data via 8 common pins, with addresses being stored in
    3.43 +latches or flip-flops, and then to employ two remaining pins to control the
    3.44 +latches. When neither latch is selected, the data pins will be used to read or
    3.45 +write data from the flash memory.
    3.46  
    3.47  In this scheme, A16 must be directly controlled by an additional pin, separate
    3.48  from the latch-based mechanism. As a result, only 14 pins are needed on the
    3.49 @@ -358,6 +380,68 @@
    3.50  Q[7...0] = 74HC273 #0 Q[7...0]
    3.51  OE# = 1
    3.52  
    3.53 +Using 74HC595 Shift Registers
    3.54 +-----------------------------
    3.55 +
    3.56 +Another solution is to map the 3 control pins directly to the Arduino, then to
    3.57 +channel addresses via a single pin to a pair of shift registers, and then
    3.58 +employ two remaining pins to control the shift registers. Eight separate data
    3.59 +pins will be used to read or write data from the flash memory.
    3.60 +
    3.61 +In this scheme, A16 must be directly controlled by an additional pin, separate
    3.62 +from the shift-register-based mechanism. As a result, only 15 pins are needed
    3.63 +on the Arduino.
    3.64 +
    3.65 +74HC595 Pinout
    3.66 +--------------
    3.67 +
    3.68 +QB  1  \/  16 VCC
    3.69 +QC  2      15 QA
    3.70 +QD  3      14 SI
    3.71 +QE  4      13 G#
    3.72 +QF  5      12 RCK
    3.73 +QG  6      11 SCK
    3.74 +QH  7      10 SCLR#
    3.75 +GND 8       9 QH'
    3.76 +
    3.77 +Arduino     74HC595#1       74HC595#2       Am29F010
    3.78 +-------     ---------       ---------       --------
    3.79 +A5                                          CE#
    3.80 +A4                                          OE#
    3.81 +A3                                          WE#
    3.82 +2           SCK             SCK
    3.83 +3           RCK             RCK
    3.84 +4                                           DQ3
    3.85 +5                                           DQ2
    3.86 +6                                           DQ1
    3.87 +7                                           DQ0
    3.88 +8                                           DQ4
    3.89 +9                                           DQ5
    3.90 +10                                          DQ6
    3.91 +11                                          DQ7
    3.92 +12          SI
    3.93 +            QA                              A0
    3.94 +            QB                              A1
    3.95 +            QC                              A2
    3.96 +            QD                              A3
    3.97 +            QE                              A4
    3.98 +            QF                              A5
    3.99 +            QG                              A6
   3.100 +            QH                              A7
   3.101 +                            QA              A8
   3.102 +                            QB              A9
   3.103 +                            QC              A10
   3.104 +                            QD              A11
   3.105 +                            QE              A12
   3.106 +                            QF              A13
   3.107 +                            QG              A14
   3.108 +                            QH              A15
   3.109 +A2                                          A16
   3.110 +5V          SCLR#           SCLR#
   3.111 +5V          VCC             VCC             VCC
   3.112 +GND         G#              G#
   3.113 +GND         GND             GND             VSS
   3.114 +
   3.115  Pins
   3.116  ====
   3.117  
     4.1 --- a/docs/COPYING.txt	Sat Aug 29 18:00:34 2015 +0200
     4.2 +++ b/docs/COPYING.txt	Tue Sep 27 00:36:33 2016 +0200
     4.3 @@ -4,7 +4,7 @@
     4.4  The following terms apply to the software, documentation and circuit designs
     4.5  provided by this project:
     4.6  
     4.7 -Copyright (C) 2015 Paul Boddie <paul@boddie.org.uk>
     4.8 +Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>
     4.9  
    4.10  This program is free software; you can redistribute it and/or modify it under
    4.11  the terms of the GNU General Public License as published by the Free Software