Let's Make Robots!

Using LED Matrix Display Chips


The Maxim7219 (datasheet) is a handy LED driver.  each chip can drive 64 LED's and several can be daisy chained for large displays, it's also used in the Blue LED Matrix Display from Oharap.

Connecting it to the Propeller is easy, it only takes 3 wires, but there aren't any pre-built objects for controlling it with the Prop, so let's build our own!

Step 1 - The Datasheet

Review the datasheet to familarize yourself with the chip.  the Max7219 uses SPI, which is what you'll use to send commands.  These commands will change the address mode, brightness, and control which LED's are illuminated.

Step 2 - SPI

SPI (Serial Peripheral Interface) is a standard for communicating with microcontrollers.  It uses 3 pins to communicate;

CS (Active Low)
When this pin is brought low, you're telling the chip to start listening for data

CLK
When you've told the chip to start listening by bringing CS low, every time you bring CLK from ground to high, it will load the status of DI into the next bit

DI
When you 'blip' CLK, if DI is high, the next bit loaded will be a 1, if DI is low, the next bit will be a 0.

Here's a diagram of how it works;
spi_thumb
(full size)

The chip is expecting 16 bits at a time.  Once the 16 bits have been sent, you'll bring CS high to tell the chip you're done issuing the command.

Step 3 - Commands

Here are the commands you'll issue the chip.  Every command is 16 bits, but the value of some bits don't matter - I've marked these bits with an X.  I've also used an underscore to help see the spacing.

1st: Set the shutdown mode to 'Normal Operation'
XXXX_1111_XXXX_XXX1

2nd: Set the decode mode
The Maxim lets you use direct addressing (control every LED individually, or Code B, which is useful when you're using a 7 segment display.  With an LED matrix, we'll use direct addressing;
XXXX_1001_0000_0000

3rd: Tell it what LED's should be turned on
Each row is mapped to a digit.  You'll need to tell the chip what row you're talking about, and which LED's are turned on for that row.  The row is defined in bits 11..8, and status of each LED is defined in bits 7..0.  Bits 15..12 are always disregarded.

Here's turning on every LED on row 0;
XXXX_0001_1111_1111
and row 1;
XXXX_0010_1111_1111

Turning on just the outside LED's on row 0;
XXXX_0001_1000_0001
and row 1;
XXXX_0010_1000_0001

Now you've got an idea of what data to send the Maxim, but how do you send it?

Step 4 - Coding

In the CON section, I've defined which pins are connected to the Max7219.  I'm also defining packet, a word sized variable that will hold the 16 bit's we'll send.

CON
DI = 0
CLK = 1
CS = 2

VAR
WORD packet

Once you've loaded up packet with the data you want to send (maybe the turn on code, or the value of a given row), let's send the data.

Make the pins on the prop outputs;
dira[di] := dira[clk] := dira[cs] := 1

Then send the packet:
packet

There you go!  The next step is making it easier to form the data you'll send the chip - think about how you'll easily load up the packet variable with the right LED pattern - this is something you'll want to do a lot!  For a few hints, download the Max7219 driver I've written here.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

If anyone is interested I have written about using the MAX7219 with Arduino. Please have a look at:

http://tronixstuff.wordpress.com/2010/07/09/review-maxim-max7219-led-display-driver-ic/