Electronic – Arduino TLC5940 and 74HC595

74hc595arduinopwmshift-register

I need to expand Arduino Uno output.
After some search I have identified 74HC595 to extend my Digital output and TLC5940 for analog output.

I'have also found how to connect them separately to Arduino Uno:

TLC5940

74HC595

This two setups share some pins, I've seen in this thread that other people use them together but I'm not sure how to connect them to my Arduino. Can you give me a hint?

Libraries are also compatible?

Best Answer

You can use them together. Both chips can be controlled by the SPI protocol.

To answer your question you first need to understand SPI:

SPI utilizes 4 data wires. They are usually called MISO, MOSI, SCLK and CS (chip select) in Arduino world. MOSI stands for master out - slave in. MISO is then master in - slave out.

You need to connect your devices like this:

Arduino   |  TLC5940   |  74HC595
MOSI (11) |  SIN (26)  |  DS (14)
SCLK (13) |  CLK (25)  |  SHCP (11)
9         |  XLAT (24) |  nothing
8         |  nothing   |  STCP (12)

If you want to connect more TLC5940 chips at once, wire all the connections as in the previous table, but connect SOUT (17) of the first chip to the SIN (26) of the next one. You will then shift twice as many bits and the bits for the furthest device will have to go first.

MOSI -> [SIN … SOUT] -> [SIN … SOUT] -> ….

If you need more 595s, connect Q7S pin (9) to the DS (14) of the next chip in the same way.

The following then applies to both of the chips, but the polarities might be different for some other devices.

When you change the polarity of SCLK from low (L) to high (H) logic level, both devices sample the data input and shift it in the internal register.

So you shift in the necessary number of bits by changing the MOSI value and cycling the SCLK pin.

Once you have all data in you change the polarity of the relevant CS from L to H to apply the internal register to the outputs. If you followed my table you have pin 8 working as CS for the 595 and pin 9 for the TLC5940.

Libraries should work unless they use configuration that is not compatible internally (timers, SPI setup..). You only need to make sure you configure the chip select pins correctly.

The details can be found in datasheets: