Go Down

Topic: MAX7219 with Arduino (Read 3 times) previous topic - next topic

imzack

Im having trouble trying to figure out how to set up the MAX7219 chip, in the startup routine....  I see there is supposed to be an ledcontrol.h file that is supposed to help.  My arduino compliler says there is no such library though....


Any suggestions on how i can get this thing programed and through the start up section?


Thanks!

Zack

CrossRoads

Here's what I did. I don't use libraries a lot, preferring to read the data sheet & understand what's going on. Doesn't make for the greatest code sometimes, and there's plenty of room for improvement.

You'll have to do some variable declarations too.
Code: [Select]

// 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,   <<< these are the addresses of the 8 data registers
 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:
 //Serial.println("shutdown register, displays on ");

}
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

imzack

Thank you so much! you even have comments!

Ill go through it here in a bit, ill see if i can get this thing working!


I appreciate it!

Zack

imzack

btw, what is SPI.transfer?  i havent seen this yet, im still kinda new to all of this.

imzack

I also see a pin called SS, what pin is this?   example "digitalWrite(SS, HIGH);

Go Up