How To Connect Shift Register To Arduino

Table of contents:

How To Connect Shift Register To Arduino
How To Connect Shift Register To Arduino

Video: How To Connect Shift Register To Arduino

Video: How To Connect Shift Register To Arduino
Video: How to Add Outputs to an #Arduino using a Shift Register - The Learning Circuit 2024, December
Anonim

In one of the previous articles, we already briefly touched on the use of a shift register, in particular, the 74HC595. Let's take a closer look at the capabilities and procedure for working with this microcircuit.

Shift Register 74HC595
Shift Register 74HC595

Necessary

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

Instructions

Step 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 the transferred state.

The pinout (pinout) is shown in the figure on the left. Their purpose is as follows.

Q0… Q7 - parallel data outputs;

GND - ground (0 V);

Q7 '- serial data output;

^ MR - reset master (active low);

SHcp - shift register clock input;

STcp - "latch" clock pulse input;

^ OE - output enable (active low);

Ds - serial data input;

Vcc - power supply +5 V.

Structurally, the microcircuit is carried out in several types of cases; I will use the one shown in the figure on the right - the output - because it's easier to use with a breadboard.

Shift register appearance and pinout
Shift register appearance and pinout

Step 2

Let me briefly recall the SPI serial interface, which we will use to transfer data to the shift register.

SPI is a four-wire bi-directional serial interface in which a master and a slave participate. The master in our case will be the Arduino, the slave will be register 74HC595.

The development environment for Arduino has a built-in library for working on the SPI interface. When applying it, the conclusions are used, which are marked in the figure:

SCLK - SPI clock output;

MOSI - data from master to slave;

MISO - data from slave to master;

SS - slave selection.

Arduino board standard SPI pins
Arduino board standard SPI pins

Step 3

Let's put together the circuit as in the picture.

I will also connect a logic analyzer to all the pins of the shift register microcircuit. With the help of it, we will see what is happening at the physical level, what signals are going where, and we will figure out what they mean. It should look something like the photo.

Wiring diagram for shift register 74HC595 to Arduino
Wiring diagram for shift register 74HC595 to Arduino

Step 4

Let's write a sketch like this and load it into the Arduino memory.

The variable PIN_SPI_SS is an internal standard constant that corresponds to pin "10" of the Arduino when used as the master of the SPI interface we are using here. In principle, we could just as well use any other digital pin on the Arduino; then we would have to declare it and set its operating mode.

By feeding this pin LOW, we activate our shift register for transmit / receive. After the transmission, we raise the voltage to HIGH again, and the exchange ends.

A sketch to demonstrate the operation of the shift register
A sketch to demonstrate the operation of the shift register

Step 5

Let's turn our circuit into work and see what the logic analyzer shows us. The general view of the timing diagram is shown in the figure.

The blue dashed line shows 4 SPI lines, the red dashed line shows 8 channels of parallel data of the shift register.

Point A on the time scale is the moment when the number "210" is transferred to the shift register, B is the moment when the number "0" is written, C is the cycle repeating from the beginning.

As you can see, from A to B - 10.03 milliseconds, and from B to C - 90.12 milliseconds, almost as we asked in the sketch. A small addition in 0, 03 and 0, 12 ms is the time for transferring serial data from the Arduino, so we have not exactly 10 and 90 ms here.

Timing diagram of Arduino exchange and shift register 74HC595
Timing diagram of Arduino exchange and shift register 74HC595

Step 6

Let's take a closer look at section A.

At the very top there is a long pulse with which the Arduino initiates the transmission on the SPI-ENABLE line - the choice of the slave. At this time, SPI-CLOCK clock pulses begin to be generated (second line from the top), 8 pieces (for transferring 1 byte).

The next line from the top is SPI-MOSI - the data that we transfer from the Arduino to the shift register. This is our number "210" in binary - "11010010".

After the completion of the transfer, at the end of the SPI-ENABLE pulse, we see that the shift register has set the same value on its 8 legs. I've highlighted this with a blue dotted line and labeled the values for clarity.

Setting the number 210 on a parallel bus via SPI
Setting the number 210 on a parallel bus via SPI

Step 7

Now let's turn our attention to section B.

Again, it all starts with choosing a slave and generating 8 clock pulses.

The data on the SPI-MOSI line is now "0". That is, at this moment we write the number "0" into the register.

But until the transfer is complete, the register stores the value "11010010". It is output to the parallel pins Q0.. Q7, and is output when there are clock pulses in the line from the parallel output Q7 'to the SPI-MISO line, which we see here.

Setting the number 0 on a parallel bus via SPI
Setting the number 0 on a parallel bus via SPI

Step 8

Thus, we have studied in detail the issue of information exchange between the master device, which was the Arduino, and the 74HC595 shift register. We learned how to connect a shift register, write data to it and read data from it.

Recommended: