Pretty involved? You write a few registers to configure it, then you send it data.
I felt it was pretty straightforward, for driving 8 7-segment+DP displays anyway.
Here is my setup code for it. Nothing fancy, just putting data in the registers with the display off to start, then setting up the rest of them.
Yeah, maybe its redundant and calling out to be rewritten as a function or something now that I re-read it 6 months later, but its clear and you have control and can see what’s going on.
And I thought it wasn’t bad for a hardware guy! And it executes quick, probably because the SPI.xxx commands are not further buried in something else (yeah, that’s my story and I’m sticking with it …)
// addresses for the MAX7221, and the values/ranges to write in
#define DECODE_MODE 0x09 // write data 0xFF, Code B Decode for all digits
#define INTENSITY_ADDRESS 0x0A // 0x07 to start, half intensity. valid from 0x00 (min) to 0x0F (max)
#define SCANLIMIT_ADDRESS 0x0B // 0xFF, all 8 digits on
#define SHUTDOWN_ADDRESS 0x0C // 0x01, normal operation (0x01 = shutdown) - powers up in shutdown mode
#define DISPLAYTEST_ADDRESS 0x0F // 0x01 = all lights on full, 0x00 = normal ops
#define leftscore_tens_address 0x01 // digit 0, leftscore_tens+left_yellow, fill right hand byte with data to display
// data = 0-9, A='-', B='E', C='H', D='L', E='P', F=blank
#define leftscore_ones_address 0x02 // digit 1, leftscore_ones+right_yellow
#define rightscore_tens_address 0x03 // digit 2, rightscore_tens+right_red
#define rightscore_ones_address 0x04 // digit 3, rightscore_ones+right_yellow
#define minutes_tens_address 0x05 // digit 4, minutes_tens+colon
#define minutes_ones_address 0x06 // digit 5, minutes_ones+left_priority
#define seconds_tens_address 0x07 // digit 6, seconds_tens+right_priority
#define seconds_ones_address 0x08 // digit 7, seconds_ones+swap
void setup() // stuff that runs once before looping forever
{
// start up SPI to talk to the MAX7221
SPI.begin(); // nothing in () because we are the master
pinMode(SS, OUTPUT); // Slave Select for SPI <--- Need this here before any SPI writes
// MAX7221: write shutdown register
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(SHUTDOWN_ADDRESS); // select the Address,
SPI.transfer(0x00); // select the data, 0x00 = Outputs turned off
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip:
// Serial.println("shutdown register, dislays off");
// put known values into MAX7221 so doesn't have weird display when actually turned on
// 0x0F = blank digit
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(leftscore_tens_address); // select the Address,
SPI.transfer(0x0F); // select the data
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(leftscore_ones_address); // select the Address,
SPI.transfer(0x0F); // select the data
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(rightscore_tens_address); // select the Address,
SPI.transfer(0x0F); // select the data
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(rightscore_ones_address); // select the Address,
SPI.transfer(0x0F); // select the data
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(minutes_tens_address); // select the Address,
SPI.transfer(0x0F); // select the data
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(minutes_ones_address); // select the Address,
SPI.transfer(0x0F); // select the data
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(seconds_tens_address); // select the Address,
SPI.transfer(0x0F); // select the data
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(seconds_ones_address); // select the Address,
SPI.transfer(0x0F); // select the data
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip
// MAX7221:
// write intensity register
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(INTENSITY_ADDRESS); // select the Address,
SPI.transfer(intensity); // select the data
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip:
//Serial.println("intensity register ");
// write scanlimit register
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(SCANLIMIT_ADDRESS); // select the Address,
SPI.transfer(0xFF); // select the data - FF = all 8 digits
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip:
//Serial.println("scanlimit register ");
// write decode register
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(DECODE_MODE); // select the Address,
SPI.transfer(0xFF); // select the data - FF = all 8 digits
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip:
//Serial.println("decode register ");
//display test
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(DISPLAYTEST_ADDRESS); // select the Address,
SPI.transfer(0x01); // select the data
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip:
//Serial.println("digit display test on ");
delay (100);
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(DISPLAYTEST_ADDRESS); // select the Address,
SPI.transfer(0x00); // select the data
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip:
//Serial.println("digit display test off ");
delay (100);
// write shutdown register for normal display operations
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(SHUTDOWN_ADDRESS); // select the Address,
SPI.transfer(0x01); // select the data, 0x01 = Normal Ops
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip: