Shifting in and out on shared pins?

Hi,

I’m trying to save as many pins as possible and will be using the shift in (cd4021) and shift out (74hc595) tutorials for buttons and leds.

I’m wondering if it’s possible to save acouple more pins by sharing the clock lines between shift registers and possibly the data lines. I’m guessing this should work if IN and OUT have separate latch pins but I’m far from my arduino so can’t try it out yet.

Anybody tried this?
Thanks!

share the clock line, yes. share the latch line - maybe. For data coming in, latch at any time & just ignore it. For data going out, latch any time, use Output enable to only present valid data when OE is enabled. share the data line - maybe: ATmega can certainly share, just use pinMode to determine if using as an input or output. If an output, then you need to be able to control the Output Enable if the shift-in register so you are not competing over who is driving the line.

Or, make both parts Open Collector driving the dataline, will have a High output when no one is driving, and low whenever one or the other takes it low.

Having to control the OE lines may overcome any savings you might gain otherwise.

Thanks!

The other way to save on pins is to multiplex the buttons and/or the leds. It all depends on how many LEDs and buttons you want. For example, I currently have an Arduino connected to four seven-segment LED displays, 2 rotary encoders and 4 pushbuttons using only 13 pins (which I could reduce to 11 using one external chip).

Thanks Dc, but shifting seems a better option to muxing for digital. In my case I'm currently using only 5 pins for up to 128 ins and outs (shared clock lines).