Skip to content

Latest commit

 

History

History
 
 

ShiftDriveSPI

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

#189 LED7Segment/ShiftDriveSPI

Using SPI to control a 7-segment display via a 74HC595 shift register.

▶️ return to the LEAP Catalog

Notes

In previous projects like ShiftDrive, the code has directly implemented the clock, latching and data transfer protocol expected by the 74HC595 shift register.

It's also possible to control the 74HC595 shift register using hardware SPI. Although this doesn't simplify the code or necessarily affect performance much, it does allow for expansion.

This sketch is a modification of ShiftDrive to control the ShiftDriveModule via SPI.

SPI pin mapping

Here's how the 595 register pins relate to SPI. The Arduino pins are for an Uno - see the SPI reference page for details for other boards.

74HC595 SPI Description Arduino Uno SPI Pin
DATA (DS, 14) MOSI Master Out Slave In 11
n/a MISO Master In Slave Out 12
CLOCK (SH_CP,11) SCLK Serial Clock 13
n/a SS Slave Select (in) 10
LATCH (ST_CP,12) SS Slave Select (out) any free pin

SPI Settings

Although default SPI settings may work, let's check. There are three factors:

  • maximum speed
  • bit order
  • mode

SPI Max Speed

The 74HC595 Datasheet indicates typical maximum clock frequency for the 74HC is 100MHz. OK, we'll never get near that with a 16MHz Arduino, so anything goes. There may be reasons to do with the specific circuit to throttle the clock, but in this case it's not a factor.

SPI Bit Order

Here's a summary of how the bits in the shift register are mapped to LED segments in my build:

Bit Segment
0 A - top horizontal
1 B - top right vertical
2 C - bottom right vertical
3 D - bottom horizontal
4 E - bottom left vertical
5 F - top left vertical
6 G - center horizontal
7 dp - decimal point

However the code uses bytes to represent dp,G,F..A from MSB to LSB, so I use MSBFIRST transfer.

SPI Mode

SPI modes define the clock polarity and phase. The timing diagram in the 74HC595 Datasheet shows:

  • base clock polarity is 0 (CPOL=0)
  • data captured on the clock's falling edge and data is output on a rising edge (CPHA=1)

This is "mode 0", aka SPI_MODE0.

Construction

Breadboard

The Schematic

The Build

Credits and References