Here's the connections you want.
This code was written for IDE 00223 and is kinda long, but it gets the job done.
Need to declare all the variables with addresses per the MAX7219 datasheet, Table 2.
May have to change "SS" to "SSpin" or similar.
// ***********************************************************************************************
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");
// 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:
//Serial.println("shutdown register, displays on ");
digitalWrite(SS,LOW); // take the SS pin low to select the chip:
SPI.transfer(digit0_address); // select the Address,
SPI.transfer(0xFF); // all segments on
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(digit1_address); // select the Address,
SPI.transfer(0xFF); // all segments on
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(digit2_address); // select the Address,
SPI.transfer(0xFF); // all segments on
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(digit3_address); // select the Address,
SPI.transfer(0xFF); // all segments on
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(digit4_address); // select the Address,
SPI.transfer(0xFF); // all segments on
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(digit5_address); // select the Address,
SPI.transfer(0xFF); // all segments on
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(digit6_address); // select the Address,
SPI.transfer(0xFF); // all segments on
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(digit7_address); // select the Address,
SPI.transfer(0xFF); // all segments on
digitalWrite(SS,HIGH); // take the SS pin high to de-select the chip
} // end of void setup(), ready to interact with users
void loop(){
// write intensity register - vary from 0x00 (dim) to 0x0F (bright)
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 ");
}