The LEDs arrived from Mouser and SparkFun, so I pulled out my breadboard and jumper wires and wired up the whole front panel. I only populated 16 out of the possible 32 RG LEDs simply because I got tired of puttiing in jumpers.
Sorry that it's not a great picture. The iPhone is a great device, but for getting good resolution on little colored wires and nearly-white LEDs, it's not so hot.
I wired it up, connected to my PC (you can see the SparkFun AVR programmer plugged in at the upper right of the picture.) Wrote a test driver that sequenced through the lights and tried some other combinations and downloaded it.
One light turned on...
Well, i didn't expect it to work the first time out! After some debugging with the logic analyzer I saw that it was sending only 7 bits of the first byte and then getting stuck. Looking at the code I saw the problem. Face-slap time.
Trying to save on some instructions, I changed the loop variable here to a uint8_t
void Max72xx::sendRegister(uint8_t reg, uint8_t data) {
for (uint8_t b = 7; b >= 0; b--) {
bitClear (*port, clkPin);
bitWrite (*port, dataPin, bitRead (reg, b));
bitSet (*port, clkPin);
}
for (uint8_t b = 7; b >= 0; b--) {
bitClear (*port, clkPin);
bitWrite (*port, dataPin, bitRead (data, b));
bitSet (*port, clkPin);
}
}
Anybody see the problem? Yup. 'b >= 0' will always be true with an unsigned integer variable. Changing to int8_t solved that particular problem. The next problem? The lights weren't going in the right sequence. This was a two-part bug. One was some bad code in the test driver, but the other problem wasn't clear until I took a closer look at the MAX72xx datasheet and my schematic. By switching to common-anode LEDs, I made the segment outputs of the MAX7219 correspond to the "points" of the display. I goofed in the order, though, reversing some of the lines. Once I rewired that, the test ran without a hitch. Time to produce REV C of the schematic.
If things lighten up at work a bit (fat chance), perhaps I'll be able to work on the driver for the TLC5916.
Recent Comments