hej,
some how i fixed a code to daisychain multiple max7219, have a look, it is working some how but there still some buggs, some times some max7219 just die, and i never just more then 4 max7219, at the end with 2 max7219 it works with out any problems so maybe i got some elektronic based problems,
please wirte a post or a mail if you noticed some mistakes in the code
/* code for max 7219 from maxim,
reduced and optimised for useing more then one 7219 in a row,
______________________________________
Code History:
--------------
The orginal Code where written for the wiring board by:
* Nicholas Zambetti and Dave Mellis
* Interaction Design Institute Ivrea
* Dec 2004
* http://www.potemkin.org/uploads/Wiring/MAX7219.txt
The first modification did:
* Marcus Hannerstig
* 2006
* K3, malmö högskola
* http://www.xlab.se | http://arduino.berlios.de
This Version is modified by:
* tomek ness
* Jan 2007
* FH-Potsdam
* http://design.fh-potsdam.de
______________________________________
-befor sending data make shure that the load is HIGH,
-fill all the max7219 with data. (begin with the last one)
-set the load to LOW and to HIGH again, so you will upload the data
* take care with the initiation you have to send every part to every max7219 and then upload it.
so for example if you have 5 max7219, you have to send the scanLimit 5 times befor you load it,
other wise not every max7219 will get the shit. maxInUse is keeping track of this,
just tell him how many max7219 you are uesing
*/
int dataIn = 2;
int load = 3;
int clock = 4;
int i = 0; // just a varialble
int e = 0; // just a varialble
int f = 0;
int c = 0;
int c2= 0;
int maxInUse = 4; //here you have to change this varialbe to how many max 7219 you want to use
// define max7219 registers
byte max7219_reg_noop = 0x00;
byte max7219_reg_digit0 = 0x01;
byte max7219_reg_digit1 = 0x02;
byte max7219_reg_digit2 = 0x03;
byte max7219_reg_digit3 = 0x04;
byte max7219_reg_digit4 = 0x05;
byte max7219_reg_digit5 = 0x06;
byte max7219_reg_digit6 = 0x08;
byte max7219_reg_digit7 = 0x01;
byte max7219_reg_decodeMode = 0x09;
byte max7219_reg_intensity = 0x0a;
byte max7219_reg_scanLimit = 0x0b;
byte max7219_reg_shutdown = 0x0c;
byte max7219_reg_displayTest = 0x0f;
void putByte(byte data) {
byte i = 8;
byte mask;
while(i > 0) {
mask = 0x01 << (i - 1); // get bitmask
digitalWrite( clock, LOW); // tick
if (data & mask){ // choose bit
digitalWrite(dataIn, HIGH); // send 1
}else{
digitalWrite(dataIn, LOW); // send 0
}
digitalWrite(clock, HIGH); // tock
--i; // move to lesser bit
}
}
////////////////////////////
void maxPut (byte reg, byte col) { // use this
//data = ((data & 0x01) * 256) + data1 >> 1;
//data = (data << 1) + ((data >> 7) & 0x01);
putByte(reg); // specify register
putByte(col);//((data & 0x01) * 256) + data >> 1); // put data
}
void maxIni (byte reg, byte col) { // put the initialisation to all the max 7219 in the system
int c = 0;
digitalWrite(load, HIGH);
for ( c =1; c<= maxInUse; c++) {
maxPut(reg, col); // use all 8 columns
}
digitalWrite(load, LOW);
digitalWrite(load,HIGH);
}
void setup () {
pinMode(dataIn, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(load, OUTPUT);
beginSerial(9600);
digitalWrite(13, HIGH);
//////////////////////////////////////////////initiation of the max 7219
maxIni(max7219_reg_scanLimit, 0x07);
maxIni(max7219_reg_decodeMode, 0x00); // using an led matrix (not digits)
maxIni(max7219_reg_shutdown, 0x01); // not in shutdown mode
maxIni(max7219_reg_displayTest, 0x00); // no display test
for (i=1; i<=8; i++) { // empty registers, turn all LEDs off
maxIni(i,0);
}
maxIni(max7219_reg_intensity, 0x0f & 0x0f); // the first 0x0f is the value you can set
}
void loop () {
//------------------------------------all doing the same: 3 led on and more
printString("los");
for (i=1; i<=8; i++) { // all max7219 doing the same shit (fill up led by led at every max7219 at the same time)
//c = 1;
//for (e=1; e<=8; e++) {
digitalWrite(load,HIGH);
maxPut(i, 193); //56, 192 is working
maxPut(i, 193); //60, 57 not
maxPut(i, 193);
maxPut(i, 193);
digitalWrite(load, LOW);
//delay(1);
digitalWrite(load,HIGH);
delay(200);
}
delay(2000);
for (i=1; i<=8; i++) { // a longer way to clean the dispaly
digitalWrite(load,HIGH);
maxPut(i, 0);
maxPut(i, 0);
maxPut(i, 0);
maxPut(i, 0);
digitalWrite(load, LOW);
//delay(1);
digitalWrite(load,HIGH);
delay(200);
}
delay(2000);
}