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:
| Bits | D15–D12 | D11–D8 | D7–D0 |
|---|---|---|---|
| Meaning | don't care | register address | data |
Send them most significant bit first, one per rising edge of CLK, with CS held low. The registers are few enough to list:
| Address | Register | What it does |
|---|---|---|
| 0x00 | No-Op | Nothing at all |
| 0x01–0x08 | Digit 0–7 | Eight bytes of pixels — one column of one square each |
| 0x09 | Decode Mode | A built-in digit font. A dot matrix wants this off: 0x00 |
| 0x0A | Intensity | Brightness, 0 to 15 |
| 0x0B | Scan Limit | How many digits get scanned. A matrix wants all eight: 0x07 |
| 0x0C | Shutdown | 0x00 blanks it. This is the power-up state |
| 0x0F | Display Test | 0x01 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.
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 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.
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.
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.
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.
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
Questions about this product
See what other owners have asked, and read their solutions.
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.