MAX7221 compatibility in Matrix.cpp

What you’ve got only works with MAX7219 and not the MAX7221

// sets register to a byte value for all screens
void Matrix::setRegister(uint8_t reg, uint8_t data)
{
  digitalWrite(_pinLoad, HIGH); // begin
  for(uint8_t i = 0; i < _screens; ++i){
    putByte(reg);  // specify register
    putByte(data); // send data
  }
  digitalWrite(_pinLoad, LOW);  // latch in data
  digitalWrite(_pinLoad, HIGH); // end
}

This works with MAX7221 as well as MAX7219

// sets register to a byte value for all screens
void Matrix::setRegister(uint8_t reg, uint8_t data)
{
  digitalWrite(_pinLoad, LOW); // begin
  for(uint8_t i = 0; i < _screens; ++i){
    putByte(reg);  // specify register
    putByte(data); // send data
  }
  digitalWrite(_pinLoad, HIGH);  // latch in data
  digitalWrite(_pinLoad, LOW); // end
}

the MAX7221 only shifts in when CS/Load is low…

Also, syncRow needs a similar change but I haven’t tested this

// syncs row of display with buffer
void Matrix::syncRow(uint8_t row)
{
  if (!_buffer) return;
  
  // uint8_t's can't be negative, so don't test for negative row
  if (row >= 8) return;
  digitalWrite(_pinLoad, LOW); // begin
  for(uint8_t i = 0; i < _screens; ++i){
    putByte(8 - row);                // specify register
    putByte(_buffer[row + (8 * i)]); // send data
  }
  digitalWrite(_pinLoad, HIGH);  // latch in data
  digitalWrite(_pinLoad, LOW); // end
}

Can anyone test these changes with a MAX7219 and a MAX7221? I'd like to include them, but don't have the hardware to try it out on.

mellis,
I'll try to test it this weekend. I have both chips.

However, while I'm good at using libraries, I'm not so good at making them!
But I'll give it a go. I expect I can find the lines in the .cpp using notepad, and if I change them and restart, I should be able to recompile with the changes - right?
(I've never figured out how to directly open a file that is not a sketch using the IDE. I have copied .CPP files into a blank sketch to get the formatting, though. I'm not sure if the issue is with the IDE or me!)

Anyway, I'll let you know what I find. I was surprised that the differences that I know about these two chips would have this result. If that's the case, it will / has confuse a lot of people. I do know that the LedControl library works with both chips.

I can already confirm Kyle’s observation. Using the simple “hello_matrix” example in the Matrix lib, the MAX7219 works, and the MAX7221 does not.

mellis,
OK, I’m earning my new second star! :sunglasses:

After confirming the MAX7221 did not work and the MAX7219 did, I made both changes Kyle described.
I am happy to report that with the changes, both chips now work. I tested both examples in the Matrix lib.

I need to put my MAX7219 back in the project I pulled it from, but let me know if you need any specific testing with the MAX7221.

Awesome. I committed the changes. Thanks for the report and testing, guys.