Electronic – Shift register with the Raspberry Pi

clockraspberry pishift-register

I have recently bought some 74HC595N (datasheet) shift registers to play with using my Raspberry Pi. The Raspberry Pi has a general purpose clock that I think I should be able to make use of, however I am unsure how this would work.

Should I have to programaticaly tell the data pin to go high, then tell the clock pin to go high, then pull the clock pin low again just to shift a 1 into the register?

I have written some code that uses the standard GPIO pins to send the data pin either high or low and then pulse the clock to shift the bit into the shift register, which seems to be working (although it is acting a little strange sometimes which is why I'm asking if I have the right idea about using the clock?)

I feel that I've worded the question rather poorly, but I cant think how else to explain my issue. If you have any questions I'll do my best to answer them.

EDIT: I'm wondering now if it could be acting up because of my voltage levels. The data sheet says that if you are powering the chip using 4.5v the minimum HIGH voltage is 3.15v. I'm using 5v to power it (not listed on the datasheet). It also says that if you're powering it with 6v the minimum HIGH voltave is 4.2v, so maybe I'm just not hitting the voltage threshold occasionally? I'm still interested in how to use the clock correctly though.

Best Answer

Your idea about programmatically setting the clock and data pins is correct. This technique is often called 'bit-banging'. To find out what goes wrong you should post your code.

The 5V / 3.3V issue could very well be your problem. Try to power the HC595's from 3.3V to see how that affects the problem.

The chip in the RaPi has some dedicated hardware that can be used to interface to SPI peripheral like the HC595. But unless you need to shift data out at the maximum speed the use of such a peripheral is not worth the trouble: bit-banging is much easier.

PS you talk about the clock and data pins, are you aware that there is a second clock (hold clock) that you must pulse once per transferred byte, and that there are a few other pins (reset, enable) that must also be kept at the appropriate level?