32×8 matrix/What the chip is doing/06. Sixteen bits at a time
What the chip is doing · 06 of 10

Sixteen bits at a time

Four chips share one data wire and none of them has an address. They are one long shift register with a latch on the end, which explains the register whose entire job is to do nothing.

One message is sixteen bits

Everything you say to a MAX7219 is sixteen bits long. The top four are ignored, the next four are a register address, and the last eight are the data:

BitsD15–D12D11–D8D7–D0
Meaningdon't careregister addressdata

Send them most significant bit first, one per rising edge of CLK, with CS held low. The registers are few enough to list:

AddressRegisterWhat it does
0x00No-OpNothing at all
0x01–0x08Digit 0–7Eight bytes of pixels — one column of one square each
0x09Decode ModeA built-in digit font. A dot matrix wants this off: 0x00
0x0AIntensityBrightness, 0 to 15
0x0BScan LimitHow many digits get scanned. A matrix wants all eight: 0x07
0x0CShutdown0x00 blanks it. This is the power-up state
0x0FDisplay Test0x01 lights every LED, overriding everything

Display Test is the single most useful line of code you will write on this board. It ignores your data, your brightness and your shutdown state, so if it lights the whole display then power, ground and all three signal wires are good, and whatever is wrong is in your data.

The chain has no addresses

Here is the part that explains the rest. The four chips are wired DOUT to DIN, and each one's sixteen-bit register feeds the next. There is no chip number in the message and no way to send a message to one chip alone.

One wire, four chips, no addresses
updating all four
What you want to change
Words sent
4
Bits on the wire
64
Words that do something
4
Clock ceiling
10 MHz
No chip has an address, so every chip costs a word. The four are one 64-bit shift register with a latch on the end. Send four words with CS low and each one pushes the last a chip further along; raise CS and all four take effect on the same edge, which is why a full-width animation never tears down the middle.

Data at DIN appears at DOUT 16 and a half clock cycles later. So to load four chips you send four words with CS held low, and each word you send pushes the earlier ones one chip further along. The word sent first ends up in the chip furthest away. Then you raise CS and all four latch at the same instant.

That is also why a full-width animation never tears down the middle: the whole frame lands on one edge.

Why there is a No-Op

Because of all that, talking to one chip still costs a word for every other chip on the wire — and those words have to be harmless. Register 0x00 is the harmless word. It is read, shifted along and thrown away.

To change the third chip of four, you send a No-Op, then your data, then two more No-Ops, then raise CS. A library doing a partial update is doing exactly this, which is worth seeing once even if you never write it yourself.

The power-up state

A MAX7219 comes up blanked, in shutdown, with no decoding, minimum brightness and a scan limit of one digit. The datasheet says to program it before use, and means it. MD_Parola's begin() and max7219.py's constructor both do this for every device they were told about — and for no device they were not, which is the whole of four squares in a row in one sentence.

When it does not work

The display shows the right thing on the wrong square

The words went in in the wrong order, or there are more chips on the wire than the sketch thinks. The word sent first travels furthest, so an off-by-one in the device count shifts the whole image one square along the chain.

The image tears when it updates

CS is being raised between words instead of after all of them. Everything latches on the rising edge of CS, so one rising edge per full frame gives an update with no seam; several give you a frame assembled in pieces.

Writing directly to the chips does nothing at first

A MAX7219 wakes in shutdown mode, with no decoding, minimum brightness and a scan limit of one digit. Four registers have to be set before anything appears: shutdown to 0x01, scan limit to 0x07, decode mode to 0x00 and intensity to something above zero.

How fast can I clock it?

The datasheet's minimum clock period is 100 ns, which is 10 MHz, and the front page advertises exactly that. A library using software SPI on general-purpose pins runs far slower than the limit, and it does not matter — the display holds its image without refreshing.

Where this goes next

Why only eight LEDs of each square are ever lit at once, and what that has to do with photographs of this display coming out striped.

One column at a time

Edit this page — content/books/matrix-32x8/sixteen-bits-at-a-time.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

32x8 LED Matrix MAX7219, 3-Pack

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum