0

I have the following code to write data on MAX7219 for light up a 8x8 LED Matrix:

for (i = 0; i < 8; i++)  
{          
    CLK = LOW;       
    DIN = temp & MSBIT >> i;  
    CLK = HIGH;  
}

The thing is, sadly, I just know that the code line (DIN = temp & MSBIT >> i;), must be exactly like that, otherwise the LED´s won't show the expected, but I don't understand how it works...

Please, I really need explanation because I'm stuck....

Note: variable "temp" is always a hexadecimal number like 0x20, and "MSBIT" = 0x80.

  • Please, post complete code. – leoc7 Jan 9 at 8:35
0

You have to send 16 bits to load data. The first 8 are the register the data goes into, 0 to 15, the next 8 are the data to be displayed. Registers 1-8 are the data that gets displayed, the others are used to set up: intensity, display test, normal/shutdow, decode/no decode mode, and number of digits/columns connected (such as 4 digits, or 8 for an 8x8 matrix).

In Arduino, I use hardware SPI to send data to MAX7219 - SCK, MOSI, and SS.

digitalWrite (ssPin, LOW);
SPI.transfer(addressRegister); // 0 to 15
SPI.transfer(dataToLoad); 
digitalWrite (ssPin, HIGH);

Do that for each register. The control registers only need to be written once. In Arduino, that is usually in setup(). Intensity might be changed later for brightness (0 to 15 as valid data).

In loop(), use the above to update your display for the 8 display data registers (1-8).

  • SPI default speeds of 4 MHz, MSBFIRST, SPI Mode 0 do not need to be changed. – CrossRoads Jan 9 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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