74HC595 interfacing with SPI

The 74HC595 (http://goo.gl/J9ILXZ) is a great chip for expanding output only GPIO and is normally really cheap. Normally, you bit bang an SPI like interface to send data to it but I decided to test whether it actually works using an SPI peripheral. With my trusty STM32F0 Discovery board and my good ol’ oscilloscope, I can clarify that it does indeed work! With standard SPI settings (Clock Phase on 1 edge, Clock polarity low sending 8 bits at at time MSB first), its as easy as connecting SCLK to the shift register clock input, SDAT to the shift register data input and a spare GPIO to the storage register clock (sometimes known as latch).

To test it works, I was writing 1 then 0 repeatedly to the SPI output with the hope of toggling Q0 (the least significant bit pin). After looking on the oscilloscope, it seems that this indeed does what I want and at reasonably good speed too! With the processor clock at 48MHz, an SPI prescaler of 2 produces a toggle rate of 124.6kHz, where as a prescaler of 16 produces a toggle rate of 71.6kHz. Not bad for 3 pins driving a shift register. with the SPI prescaler being 16, the serial clock is at 3Mhz. With a prescalar of 2, the calculated clock should be at 3*8 = 24MHz but my logic analyzer can’t measure that high and produces an aliased output. It seems the limit of the speed is down to the GPIO toggles for the latch.

Measuring the SPI and shift register output with a prescaler of 2. Note the aliased clock apparently at 82.7kHz

Measuring the SPI and shift register output with a prescaler of 16. The clock isn’t aliased and can be seen at 3Mhz.

Oscilloscope view of the clock and output toggle rate. Sorry for the noise on the lines! I only had one grounding cable.
The experimental setup, long oversized leads everywhere! Probably why the oscilloscope pics are so poor.

I’ll hopefully be using this cheapo GPIO expander on one of my future watches. With no load at 2.98v, the device consumes a whole 23uA (prescaler of 2). With a prescaler of 16, this current nearly halves to 13uA. When writing nothing to the device at all, the current becomes immeasurable by my tools.


Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s