Shift register hacks

The parallel-in shift register brigade is a really simple way to get a lot of input data into your microcontroller. It has the downside of requiring external pull-up resistors and not allowing for external interrupts, but it is fast and requires only 3 microcontroller pins. But, what if you don’t have 3 free pins? Well, we have a solution for you that only requires 2 free pins.

2 pin shift register hack

Figure 1 – 2 pin shift register hack.

Basically, the latch pin is multiplexed with the data, such that it is held high when the clock is active. This keeps the data fixed during shifting, but allows the latches to become transparent once shifting is done. Care must be taken to make the decay time on the capacitor long enough so that it doesn’t reset during clock pulses, but short enough that it resets between samples. This shouldn’t be difficult as long as the clocking operation doesn’t get interrupted. If it is running on the SPI bus, this should never happen.

But, what is that you say? You don’t even have 2 free pins? Your dog ate all your I/O? Well here is a solution for only 1 pin.

1 pin shift register hack

Figure 2 – 1 pin shift register hack.

This is an extension of the previous setup, except now all three pins are multiplexed onto the same line. The latch works the same as before, but now there is a resistor to the data pin, so the clock can drive the shift register without fighting too hard with the data line (since they are both outputs). Once the next bit of data is clocked out, the microcontroller switches to input and reads the data. It then switches back to output and clocks the next bit. This all can be done rather quickly.

Depending upon the size of your data pin resistor, you might need to disable pull-ups during data read. This is to be avoided as it takes more time, and risks double clocking the shift register. If you are going to switch pull-ups on and off, its important that this is done after the I/O pin is set to input. Otherwise the clock line might go low and high during the direction transition and shift the next bit by accident. Good starting values for this design are 2.2k for the data resistor, 100pF for the capacitor, and 100k for the latch resistor.

Next you’re going to tell me you don’t have any free pins, and that you want to teleport the data into the chip somehow. Sorry, I don’t have a solution for that yet. But keep checking back!