How to connect the shift register to Arduino

In a previous article we have already briefly related to the application of shift register, in particular, the 74HC595. Let’s take a closer look at the procedure and possibility of working with this chip.


Как подключить сдвиговый регистр к Arduino

You will need

  • — Arduino;
  • — shift register 74HC595;
  • — connecting wires.

Manual

1. Shift register 74HC595 and the like are used as devices for converting serial data to parallel, and can also be used as a «latch» for data holding transferred to the state.
The scheme of the leads («pinouts») are shown in the figure on the left. Their purpose is.
Q0…Q7 outputs the parallel data;
GND — ground (0V);
Q7′ output the serial data;
^MR — master reset (active low);
SHcp is the clock input of the shift register;
STcp — clock input «block»;
^OE — output resolution (active low);
Ds — the input serial data;
Vcc — power supply +5 V.
Structurally, the chip is performed in several types of cases; I’ll use the one shown to the right — lead — because it is easier to use with the development Board (bridbord).


Как подключить сдвиговый регистр к Arduino

2. I will shortly remind about the serial interface SPI, which we will use to transfer data into the shift register.
SPI is four-wire bidirectional serial interface, which is attended by master and slave. Leading in our case will be the Arduino, the slave — register 74HC595.
Development environment for Arduino has a built-in library works on SPI interface. Its application will use the findings, which are marked in the figure:
SCLK is the clock output SPI;
MOSI — data from the master to the slave;
MISO — data from slave to master;
SS — slave select.


Как подключить сдвиговый регистр к Arduino

3. Let’s put the circuit as in the figure.
I will also connect to all legs of the chip of the shift register logic analyzer. With it, we’ll see what happens on the physical level, what signals go where, and figure out what they mean. It will look like as the pictures.


Как подключить сдвиговый регистр к Arduino

4. Write here is a sketch and upload to Arduino memory.
Variable PIN_SPI_SS is the internal standard constant that corresponds to the output «10» when using the Arduino as the master device SPI interface, which we use here. In principle, we could just as well use any other digital output of the Arduino; then we would have had to declare it and set its mode of operation.
Feeding on this conclusion is LOW, we will accelerate our shift register to the reception/transmission. After the transfer we again raise the voltage to HIGH, and the exchange ends.


Как подключить сдвиговый регистр к Arduino

5. Enable our scheme to work and see what will show us the logic analyzer. General view of the timing diagram in the figure.
The blue dotted line shows the 4 lines SPI, dotted red — 8 channels of parallel data of the shift register.
Point A on the timeline is the time of the transfer in the shift register the number «210», B — time of recording «0», C — repeat cycle from the beginning.
As can be seen, from A to B — 10.03 milliseconds, and from B to C — 90,12 milliseconds, almost as specified in the sketch. A small additive of 0.03 and 0.12 MS is the time of serial data from the Arduino, so we are not exactly 10 and 90 MS.


Как подключить сдвиговый регистр к Arduino

6. Let us consider the plot of A.
At the top — long impulse, which Arduino initialisere transmission line SPI-ENABLE — slave select. At this time, begin to generate clock SPI-a CLOCK (second line from top), 8 pieces (for 1 byte).
The following line — SPI-MOSI is the data that we transmit from the Arduino to the shift register. This is our number «210» in binary is «11010010».
After the transmission is completed, the end of the pulse SPI is ENABLE, we see that the shift register is put on his 8 legs the same value. I highlighted it in blue dotted line and signed values for clarity.


Как подключить сдвиговый регистр к Arduino

7. Now let’s look at the plot B.
Again, it all starts with the slave select and generate 8 clock pulses.
The data on the line SPI-MOSI is now «0». That is, we record this time into the register number «0».
But until the handover is completed, the register stored value «11010010». It appears to parallel the findings Q0..Q7, and is issued in the presence of clock pulses in lines c parallel output Q7′ in-line SPI-MISO, what we’re seeing.


Как подключить сдвиговый регистр к Arduino

8. Thus, we examined the issue of information exchange between the master, which was made by Arduino and shift register 74HC595. Learned how to connect a shift register to store data in and read data from it.