# [Solved] Start problem with the 8*8 LED dot matrix

This is the problem:

Dot matrix start problem

Here is my code:

``````void SPI_Init(void);
void SPI_TX(uint8_t data);
void MAX7219_init(void);
void draw(void);
void clr(void);

void setup() {
SPI_Init();
MAX7219_init();
}

void loop() {
clr();
_delay_ms(100);
draw();
}

void SPI_Init(void)
{
DDRB |= (1<<DDB3)|(1<<DDB5)|(1<<DDB2); // DDB3 MOSI, DDB5 SCK, DDB2 SS
SPCR = (1<<SPE)|(1<<MSTR);  // SPI enable, Master Mode
}

void SPI_TX(uint8_t data)
{
SPDR = data;
while(!(SPSR & (1<<SPIF)));
}

void MAX7219_init(void)
{
PORTB &= ~(1<<PB2);
SPI_TX(0x0C); // shutdown
SPI_TX(1);
PORTB |= (1<<PB2);
PORTB &= ~(1<<PB2);
SPI_TX(0x0A); // intensity
SPI_TX(1);
PORTB |= (1<<PB2);
PORTB &= ~(1<<PB2);
SPI_TX(0x09); // decode mode
SPI_TX(0x00);
PORTB |= (1<<PB2);
PORTB &= ~(1<<PB2);
SPI_TX(0x0B); // scan limit
SPI_TX(0x07);
PORTB |= (1<<PB2);
}

void draw(void)
{
uint8_t descend[9]={9,8,7,6,5,4,3,2,1};
uint8_t ascend[9]={0,1,2,3,4,5,6,7,8};
uint8_t i,k,p,device=0,offset;
uint8_t row=4,col=5;  // suppose are func args
for (i=0;i<9;i++)
{
for (k=1;k<9;k++)
{
PORTB &= ~(1<<PB2);
SPI_TX(k);
/*if ((k % 2)==0)
{
SPI_TX(0);
}*/

for (p=0;p<device;p++)
{
SPI_TX(0x00);
}

PORTB |= (1<<PB2);
}
//device++;
_delay_ms(200);
}
}

void clr(void)
{
uint8_t i,k;
for (i=1;i<10;i++)
{
PORTB &= ~(1<<PB2);
SPI_TX(i);
SPI_TX(0x00);
PORTB |= (1<<PB2);
}
}
``````

You should ask the moderator to move your post to the LEDs and Multiplexing forum.

Instead of making us watch a video.

1. Tell us which type of 8x8 LED matrix did you buy.
2. Tell us the schematic you used.
3. Tell us the Arduino library you are using.

ieee488: You should ask the moderator to move your post to the LEDs and Multiplexing forum.

Instead of making us watch a video.

1. Tell us which type of 8x8 LED matrix did you buy.
2. Tell us the schematic you used.
3. Tell us the Arduino library you are using.

Where is that forum? I could not find it.

dot matrix 4 modules

1. It's simple direct connection to my Arduino Nano board. Here's another video: dot matrix 4 modules

2. It's my own AVR C code.

Problem solved.

I have to initialize it properly.

``````void SPI_TX(uint16_t data)
{
SPDR = data>>8;
while(!(SPSR & (1<<SPIF)));
SPDR = data;
while(!(SPSR & (1<<SPIF)));
}

void MAX7219_init(void)
{
PORTB &= ~(1<<PB2);
SPI_TX(0x0A00); // intensity
PORTB |= (1<<PB2);
PORTB &= ~(1<<PB2);
SPI_TX(0x0900); // decode mode
PORTB |= (1<<PB2);
PORTB &= ~(1<<PB2);
SPI_TX(0x0B07); // scan limit
PORTB |= (1<<PB2);

PORTB &= ~(1<<PB2);
SPI_TX(0x0F00);
PORTB |= (1<<PB2);

for (i=0;i<4;i++)
{
PORTB &= ~(1<<PB2);
SPI_TX(0x0C01); // shutdown on
PORTB |= (1<<PB2);
}
}
``````