1

I'm using a max7219 like this one max7219. When I first tested my circuit, I used an 8x8 display and the code worked just fine. Now, after I modified the code and changed the display with the chained one, the text is showing only on the first matrix. I've seen someone that had another problem with the same matrix module, only that in his case the same text was printed on all the matrixes unsolved problem, in the end he didn't find a solution. Below, I'll attach my code. Please help me find the problem.

//Pin connected to ST_CP of 74HC595
int latchPin = 6;
//Pin connected to SH_CP of 74HC595
int clockPin = 7;
////Pin connected to DS of 74HC595
int dataPin = 5;

int period = 30;

byte rotl(byte n, byte b)
{
  return (n << b) | (n >> (8 - b));
}

byte X[] {

0x80,
0x80,
0x80,   //L
0x80,
0x80,
0x80,
0x80,
0xFF,

/*0x10,
0x00,
0x10, //I
0x10,
0x10,
0x10,
0x10,
0x10,

0XF0,
0x90,
0x80, //C
0x80,
0x80,
0x80,
0x90,
0xF0,

0xF0,
0x09,
0x09,
0x09,
0x09,
0x09, //A
0x09,
0xF0*/

};

void setup() {
  //set pins to output so you can control the shift register
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}

void loop() 
{
  for (int i = 0; i < 8; i++)
  {
    X[i] = rotl(X[i], 1);
  }
  for(int i = period;i>0;i--)
  {
    displayX();
  }

}

void DisplayMatrix(byte numCol, byte numLine)
{
  byte numberToDisplay1 = numCol;  
  byte numberToDisplay2 = numLine;  


  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay1);  
  shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay2);  
  digitalWrite(latchPin, HIGH);
  delay(1);

}

void displayX()
{
   DisplayMatrix(X[0],1);
   DisplayMatrix(X[1],2);
   DisplayMatrix(X[2],4);
   DisplayMatrix(X[3],8);
   DisplayMatrix(X[4],16);
   DisplayMatrix(X[5],32);
   DisplayMatrix(X[6],64);
   DisplayMatrix(X[7],128);
}
2
  • 1
    I don't think you understand how the protocol works. Have you read the MAX7219 datasheet?
    – Majenko
    Commented Aug 22, 2016 at 10:26
  • Why don't you just get a copy of the library that drives the max7219 ?? playground.arduino.cc/Main/LEDMatrix. Commented Aug 22, 2016 at 11:33

1 Answer 1

3

Communicating with more than one MAX7219 chip when cascaded involves sending data to all the chips at once. You have to treat the cascaded sequence of chips as a single entity - an entire display in its own right.

With one chip you send an 8-bit register value followed by an 8-bit data value. To use two chips you have to send twice that - an 8-bit register and 8-bit data for the second chip, followed by an 8-bit register and 8-bit data for the first chip.

The chips have a "NO-OP" register (0x00) which can be used to ensure that nothing is done on that chip if you don't want to change anything.

So setting line 3 to 0x55 on the first display, and line 5 to 0xAA on the second display you would send the sequence \ 0x05,0xAA,0x03,0x55 / as a single transaction (lower CS \ before, raise it / afterwards).

If you only wanted to set line 2 on the second display to 0x69 you would send the sequence: \ 0x02,0x69,0x00,0x00 /

For three chips you need to send three blocks of 8+8 values. For four chips, 4 blocks of 8+8. Etc.

Note that it is important to send enough data for all the chips - you can't shortcut and only send data for the first display if that is all you want to talk to, since whatever is currently in the first display's shift register will get sent out to successive chips, and you will get the display duplication as seen in the other question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.