SN74HC595: Shift Register

The objective of this post is to perform a brief analysis of the SN74HC595 shift register and its working principle.


The SN74HC595 devices are 8-bit Serial-In, Parallel-Out Shift Registers [1], which basically means that, for example, a microcontroller can communicate with the device by a serial interface and then the SN74HC595 makes that data available in a parallel format (in this case, the 8 bits).

This functionality is very useful since we can extend the number of pins a microcontroller can control. Thus, in this case, as we will see next, we can control 8 output bits with only 3 digital pins from a microcontroller. A typical use case is controlling multiple LEDs.


Internal structure and operation

Internally, the device is composed of 2 registers, with 8 bits (which is the same as 8 memory positions) each. The first one, a shift register, will feed a second one, a storage register. Figure 1 illustrates the internal structure.

74HC595 registers

Figure 1 – Representation of the internal structure of the SN74HC59. “X” means undefined.

Naturally, we first need to load data to the shift register and then transfer it to the storage register. Figure 1 represents a possible state where some data as already been loaded to the shift register but none has been loaded to the storage register.

Notice that the serial input signal corresponds to the data that is transferred to the shift register of the SN74HC595 to latter be accessible in the parallel output. Since we have 8 output data bits, we typically want to pass 8 input data bits each time. This is an external signal and is accessible in a pin of the integrated circuit.

The clock signal, which is also an external signal available through a pin, controls the loading operation of data to the shift register.

Figure 2 illustrates the process of loading the serial data from the serial input.

74HC595 load serial data.png

Figure 2 – Process of loading serial data to the shift register. The arrow pointing up in the clock signal represents a positive edge of the signal.

As can be seen, when a positive edge occurs in the clock signal, the data in the serial input pin is transferred to the SN74HC595 as one bit. Internally, the first memory position of the shift register is set to the value of the serial input (HIGH = 1 or LOW = 0) and the other memory positions will get the values from the previous memory positions (thus shifting).

As represented in the figure, the bit that was in the last memory position of the shift register is “lost” when the shift occurs. Nevertheless, we can obtain that bit in a output pin of the IC. This allows, for example, to cascade multiple of these ICs, allowing to control even more output pins, with the exact same number of digital pins from a microcontroller.

So, since we already have data in the shift register, we can now signal the device to transfer those bits to the storage register. Then, each bit of the storage register will correspond to the 8-bit parallel output, available through pins of the integrated circuit. Figure 3 illustrates the procedure.

74HC595 load from shift to storage register

Figure 3 – Loading of data from the shift register to the storage register.

As can be seen, the output bits are stored in the storage register and the transfer procedure is started by a rising edge in a specific signal, which is controlled externally to the device and exposed in one of its pins.

The serial input, the clock and the load signals are the main ones needed to control the state of the device and are, in typical applications, generated by a microcontroller.


Pin mapping

Figure 4 shows the pin mapping of the SN74HC595.


Figure 4 – Pin mapping of the 74HC595. Taken from [1].

Pins from QA to QH are the parallel outputs (8 bits). From a functional point of view, if we connect the device to a microcontroller, those will be 8 extended digital output pins. As we seen in the previous section, these pins correspond to the 8 bits stored in the memory positions of the storage register.

The SER pin corresponds to the serial input data, also mentioned in figures 1, 2 and 3.

The SRCLK is the shift register clock and is, as mentioned, positive edge-triggered [1]. So, when a positive edge occurs, the data in the SER pin is transferred to the SN74HC595 as one bit, to the first position of the shift register. Naturally, since we are operating with groups of 8 bits, we typically expect for 8 positive edges of SRCLK to pass all the data.

The RCLK pin corresponds to the signal to load data from the shift to the storage register, also mentioned before. Then, those bits will be available in pins QA to QH. Naturally, those pins will maintain the value until we send more bits with the previously mentioned method. This pin is also activated with a transition from LOW to HIGH.

The OE pin is the output-enable pin. The line on top of its name means that it is active-low. In order words, we need to connect it to LOW for the QA to QH pins to be in an HIGH or LOW state. Otherwise, if we connect that pin to HIGH, the QA to QH pins will be disabled (high-impedance state) [1]. In typical applications, we connect it directly to GND.

The SRCLR pin allows to clear the shift register and is an active-low pin [1]. For typical uses, we connect it to VCC, since we can clear the content of the shift register by sending LOW values by the serial interface.

Finally, the QH’ pin is the one where we can obtain the discarded bit of the shifting procedure. Explaining the procedure of cascading these ICs using this pin is outside the scope of this post and for applications that use just one SN75HC595 it can be left unconnected.


Operating conditions

As stated in the datasheet of the device, the recommended supply voltage should be between 2 V and 6 V [1]. This means that it can be used by both a regular Arduino operating at 5 V and also an ESP8266 operating at 3.3 V.

The absolute maximum output current per pin is 35 mA [1]. Nevertheless, the maximum continuous current through VCC or GND is 70 mA [1]. So, we should be careful to avoid that the sum of current of all pins becomes greater than this threshold.


Final Notes

The SN74HC595 is a very common device that has been used by makers for a long time. Thus, it’s a well known IC and there are lots of great tutorials around the web on how to use it with multiple microcontrollers, such as the Arduino.

Nevertheless, I decided to create this post as a starting point for future tutorials on how to control the SN74HC595 from an ESP8266.

I would also like to say that there are 74HC595 ICs from multiple manufacturers, but the working principle should be the same and thus, future tutorials should be compatible with them. This tutorial was based on the SN74HC595 from Texas Instruments.


Related Posts







8 Replies to “SN74HC595: Shift Register”

  1. You could show example sketches for transferring data. A standalone sketch for one, another using the Adafruit LCD backpack library would be a great example, and then code for using the SPI library.

    Liked by 1 person

      1. Thanks. The reason I was hoping for an SPI implementation is because I tried that a few years ago with limited success, hoped you would have better luck. I had an application that needed the SPI library to interface a CAN chip set so it would save code space and I/O pins to use the 595 as just another SPI device to manage the LCD display. I am not a programmer and have trouble understanding the C++ libraries, but I determined that the Adafruit LCD backpack code did not use SPI, it has it’s own bit banging routine.

        Liked by 1 person

        1. I’ve uploaded today a post on how to interact with the 595 using an SPI interface 🙂 Although I tested it on the ESP8266, it should work on an Arduino:

          Regarding to Adafruit’s library, I’ve never used it. I’ve had success interfacing with 16X2 and 20X4 LCDs using an I2C adapter (which can be bought along with the LCD and already soldered at eBay) and liquid crystal I2C library:

          Unfortunately, I never interfaced with those kinds of LCDs via SPI/shift registers. Nevertheless, I found this library that seems to be tested with SPI and the 74HC595 and may be of help (it also contains a wiring diagram in the page):

          If I learn anything new, I’ll share in a post or a comment.

          Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s