Go Down

Topic: [Solved] Start problem with the 8*8 LED dot matrix (Read 294 times) previous topic - next topic

wolfrose

Jan 04, 2018, 12:06 pm Last Edit: Jan 14, 2018, 10:38 am by wolfrose
This is the problem:

Dot matrix start problem


Here is my code:

Code: [Select]
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 data_mask[5]={3,5,7,9,0x0A};
  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);
      }*/  
      SPI_TX(data_mask[0]);
        
        for (p=0;p<device;p++)
        {
          SPI_TX(0x00);
        }
    
      PORTB |= (1<<PB2);
    }
    data_mask[0]<<=1;
    //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);
   }
}  



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.


wolfrose

#2
Jan 08, 2018, 01:25 pm Last Edit: Jan 08, 2018, 01:33 pm by wolfrose
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.

1. It's the one connected with MAX7219 chip.
I have both of these:
https://www.aliexpress.com/item/MAX7219-Dot-Matrix-Module-LED-Display-Module-For-Arduino-MCU-Control-Driver-3-2-3-2/32788194408.html?spm=2114.search0204.3.267.DMHq4e&ws_ab_test=searchweb0_0,searchweb201602_1_10152_10065_10151_10344_10068_10342_10343_10059_10340_10314_10341_10534_100031_10084_10604_10083_10103_10613_10307_10615_10614_10142,searchweb201603_6,ppcSwitch_2_ppcChannel&algo_expid=d0c04e05-af90-4406-89ff-b1fb88a3f8a9-40&algo_pvid=d0c04e05-af90-4406-89ff-b1fb88a3f8a9&priceBeautifyAB=0]MAX7219 dot matrix 8x8]LED dot matrix 1 module

dot matrix 4 modules

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

3. It's my own AVR C code.


wolfrose

Problem solved.

I have to initialize it properly.

Code: [Select]
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);
  }
}

Go Up