I Have started making my 1st PCB, as per my other question (Located Here) and have been looking at the datasheet for the MAX7219CNG and studying the library to run it on an Arduino (Located Here)

Now my question is from what I can see in the library, there is a method called spiTransfer that sends the data to the IC to turn on and off the various LEDs. This is done by shifting data containing opcode and data bits. The opcodes are at the top of the .cpp file. For example #define OP_SHUTDOWN 12

I can't find where the related information is in the datasheet to say that 12 = Shutdown.

Am i reading the datasheet wrong or understanding the library wrong. I want to learn how to read a datasheet and implement code to run an IC with out relying on code written by others.

And guidance would be great thanks


1 Answer 1


That's because it's in the datasheet in hex. :-) Page 7, table 2. I'd have written the define as #define OP_SHUTDOWN 0x0C to be consistent with the datasheet…

  • \$\begingroup\$ Thanks, that helps a lot. I take it that most SPI communications are the same, in you shift op codes then the data length of each depends on the data sheet? \$\endgroup\$ Jan 1, 2011 at 23:48
  • \$\begingroup\$ I think it's more likely that they are all the same size (a byte in this case). The library is just badly written. Control commands (they're not really opcodes) should generally be written in hex, or whatever format the datasheet uses. Mixing bases is a recipe for disaster/unmaintainability. \$\endgroup\$ Jan 2, 2011 at 5:05
  • 1
    \$\begingroup\$ Well my plan is to rewrite the library if for nothing else than the learning value. I will make sure that I use hex values instead of decimal values to keep with the datasheet \$\endgroup\$ Jan 2, 2011 at 9:46
  • 1
    \$\begingroup\$ When you do rewrite it - please post it somewhere! \$\endgroup\$
    – RQDQ
    Jan 3, 2011 at 0:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.