2
\$\begingroup\$

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

\$\endgroup\$
6
\$\begingroup\$

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…

\$\endgroup\$
  • \$\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\$ – Ashley Hughes Jan 1 '11 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\$ – Connor Wolf Jan 2 '11 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\$ – Ashley Hughes Jan 2 '11 at 9:46
  • 1
    \$\begingroup\$ When you do rewrite it - please post it somewhere! \$\endgroup\$ – RQDQ Jan 3 '11 at 0:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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