NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » LED Array with Max7219 Programming Clarification ?

March 31, 2011
by uml_12

This could be a fairly simple answer if my understanding is correct.

My project is an electronic puzzle that lights up different LEDs in an array for different levels. I'll spare you the bulk of my setup for I don't think it is immediately needed for this question. I'm using SPI connection from the Atmega328 to 1) a single Max7219 and then 2) Three Max7219's in series .. Dout -> Din.

So I'm just going to run down my understanding in the last few days. These steps begin after all the includes and what not .. basically for testing purposes, I'm just going to put these steps in Main{}

A) Set variable X0 to be the first byte (8bits) of information which on the Max7219 corresponds to D15-D8. Where D11-D8 are the digit selectors. Since I want to do this in order 0 -> 7, I wish to set X0 to be the 0th digit on the display.

Set variable Y0 to be the second byte of information which corresponds to D7-D0. Where D7-D0 are the segment selectors for the 0th Digit selected by X0.

B) Initialize the registers of the Max7219

• power On

• Set Decode mode

• scan limit

• Intensity

• Test off

• Send Digits 0-7

C)

• Set clk, din, load = low

D) Use a FOR loop to analyze the 8 bit packet of X0:

• At the start of the loop, clk and Din are set to 'low',

• Then if the next bit in line is a 'high' we set Din to 'high',

• Else, we wait 1ms and then set clk to 'high'

• Then we left shift X0 by 1 bit

• The loop is repeated 8 times.

Step (D) is for the purpose of analyzing which digit position on the array (0->7) we would like to allocate data to.

E) Use a FOR loop to analyze the 8bit packet of Y0:

• At the start of the loop, clk and Din are set to 'low',

• Then if the next bit in line is a 'high' we set Din to 'high',

• Else, we wait 1ms and then set clk to 'high'

• Then we left shift X0 by 1 bit

• The loop is repeated 8 times.

Step (E) is for the purpose of determining which segments will be lit at the particular digit position specified by X0.

F)

• Now we set Latch to 'High' (16 clock cycles later) so that the max7219 retains the data that has just been sent.

Okay, so plz let me know if any of these steps are missing information and indicate which step you are referring to.

Question 1

I think I understand now that I realized I overlooked the fact that the Max7219 has 8x8 static ram. But for clarification, this means that to light up all 8 digit positions on the LED array, I need to pass 64 bits of information (X0,Y0,X1,Y1,X2,Y2...X7,Y7) from the Atmega328 to the Max7219, in packets of 16 bits, setting Latch to 'High' at the end of each packet transmission ?

Question 2: Cascading 3 Max7219's via SPI:

(1)Max7219 -> (2)Max7219 -> (3)Max7219 .. All in series; Dout -> Din.

Again, just so I don't spend countless hours questioning my logic .. look at my steps here:

• Send (1)Max7219 64bits of information, Latch at the end of transmission (as well as at the end of each 16bit transfer *covered this above)

• Send (1)Max7219 another 64bits of information, Latch at the end of transmission. Now the first 64bit packet exist within (2)Max7219

• Send (1)Max7219 a third 64bit packet, Latch at the end of transmission. Now (1)Max7219 contains the third 64bit packet transferred while (3)Max7219 contains the first 64bit packet transferred.

## Does this look right?

Question 3:

Okay, so we covered a single Max7219 and a cascade of 3 Max7219s serial connected. The Max7219 display driver allows the user the ability to control the number of digit positions displayed. The amount of positions I want to display for each of the three Max7219's = 6 positions (0->5). The other positions are not important to me (They will be left floating).

How does this affect my data? How many 16bit packets will each Max7219 now be able to hold? Do I transmit the same 64bit packet and imagine that the excess bits that control the output of digits 6 and 7 will be Do Not Cares (X's)? Or does this decision make each Max7219 hold less data and therefore shift excess bits out to the next serially connected Max7219 prematurely?

:::::::::::::::

Thank you to anyone that can help me! It's been a long week and I'm ready for some answers.

• Jeff
March 31, 2011
by Noter

I think you've got it pretty well figured out on the steps. It all looks right to me. I'm sure the max7219 assumes all the segment and digit lines are connected so you will have to give all the bits every time. Bit values for the missing led's will make no difference.

You could use the ATmega built-in SPI interface and it would shift out the data for you. I've used it on other serial shift registers and it worked fine.

April 20, 2011
by uml_12

I've been working on this for a while and one thing I'm not really sure about is the timing diagram on the max7219 datasheet.

http://datasheets.maxim-ic.com/en/ds/MAX7219-MAX7221.pdf

On page 1, I see that it is a 10Mhz serial interface. Does that mean that I must sent the 16 bits at a rate of 10Mhz ? And the atmega168 runs at 14.75.. Mhz. So with a bit bang method, do I need to adjust for this difference. I'm aware that with SPI enabled, I can set the frequency accordingly. However, I have not actually been able to get anything to do with SPI working as of yet. So for now, I might stick to the bit by bit method. At least I have a better idea of where it might be getting hung up.

Looking at the timing diagram of the 7219 datasheet on page 6, I'm seeing some delays involving how the data sent is lined up with the clock output of the 168. For reference, I'v been toying with the code seen here:

http://pastebin.com/N7Jduzpv

I can't really tell if the nano second intervals are enough to make a difference in the code I'm working with. My next attempt is to add delays into the code which corresponds to the diagram. But as of right now, I get no output on the max7219 on any of the segments.

Any ideas on what could be the issue ?

April 20, 2011
by uml_12

Ah .. nevermind, I seemed to have succeeded on using the test mode. Which is nice because it's the first time iv gotten any leds to light up for the past two weeks. I'm content.