LED 8x8 dot matrix start problem

Go To Last Post
20 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm working on my LED 8x8 dot matrix pixel write functions, but like most the times the module work start directly. It flashes couple times or one time and stays on, I then have to unplug and plug it again and again until it starts properly.

 

I recorded a video on YouTube:

 

https://www.youtube.com/watch?v=eRuXVBWh5t8

 

 

And this is my code on Arduino IDE:

 

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();
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,offset=0x07,pixels=1;
  uint8_t row=4,col=5;  // suppose are func args
  for (i=1;i<10;i++)
  {
    for (k=0;k<9;k++)
    {
      PORTB &= ~(1<<PB2);
      SPI_TX(k);
      if (k==5 || k==4 || k==2 || k==7)
      {
        SPI_TX(0);
      }
      //_delay_ms(20);     
        SPI_TX(offset<<=1);
      //_delay_ms(20);
      PORTB |= (1<<PB2);
    }
    _delay_ms(300);
    //offset<<=1;
  }
}

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

 

This topic has a solution.

Last Edited: Thu. Jan 18, 2018 - 10:21 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

so put some prints in to see where it's actually hanging...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

So... this should be in the Arduino forum. Surely not that difficult?

 

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But I don't deal with it as an Arduino board, it's an AVR chip and the code in C, just I'm writing and uploading the code by Arduino IDE. I think it's like I have an AVR dev board.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes but... the Setup() + Loop() - Main() structure is typically Arduinoese.

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

At 1:09, the module got the right start signal and the program started to work, it's shifting data. But the problem is there even if I upload an empty code.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A schematic would help. I can not tell from video if you have adequate bypass caps and what loads you are driving with the AVR.

From the video, I would suspect possibly something to do with the power...

David (aka frog_jr)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

valusoft wrote:
Yes but... the Setup() + Loop() - Main() structure is typically Arduinoese.

and you're using the Arduino framework and Arduino IDE.

 

So this is very much an Arduino project - even if it's not actual Arduino hardware.

 

Have you tried it on actual Arduino hardware - that would tell you whether it's an issue with your AVR hardware, or your software ...

 

Again, put in prints so that you can see what it's doing.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To be sure of what is happening, I connected my PIC18F4550 with this module and the MAX7219 isn't even working from last night! It's really weird the same C code and I did the necessary modifications to the MPLAB environment C code but it's not working! This explains how Arduino platform is easy to use :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No, the problem is not the module is not working at all, it's just an issue at the start when I plug the Arduino USB to the laptop. I don't know what exactly the signals which flashes the module randomly until it initialized properly.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

wolfrose wrote:
it's just an issue at the start when I plug the Arduino USB to the laptop.

I cannot see if you have bypass caps on your breadboard, but many older laptops and some new ones USB ports are not capable of sourcing more than 100ma of current.  I would suspect that your circuit may be drawing surges that are causing the port to sag which in some cases the AVR can handle, sometimes not.

 

Do you have a Cell phone charger that has the 2.1amp output capacity?  I would try that.

 

Is the MAX7219,h file part of the Arduino environment?  Save me from searcning wink

 

For now, my bet is on the lack of bypass caps, and maybe the pullup resistor on the AVR not being 10k, along with an inadequate power supply.

 

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I posted a video on YouTube:

https://www.youtube.com/watch?v=-qO-QLI4vyw

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Your video does not address the comments in #11! The arduino page for the max7219 outlines the same comments - random operation might occur if you do not follow these recommendations. What are you observing? Random operation? The solution is???

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Problem solved.

 

With this arrangement:

 

void SPI_TX_s16(uint16_t data)
{
    PORTB &= ~(1<<PB2);
    SPDR = data>>8;             // send high byte
    while(!(SPSR & (1<<SPIF)));
    SPDR = data;                // send low byte
    while(!(SPSR & (1<<SPIF))); 
    PORTB |= (1<<PB2);
}

void MAX7219_init(void)
{ 
  SPI_TX_s16(0x0A00); // lowest intensity
  SPI_TX_s16(0x0900); // decode mode normal
  SPI_TX_s16(0x0B07); // scan limit normal speed
  SPI_TX_s16(0x0C01); // shutdown on
}

 

But I have another question:

 

I want to combine multiple SPI transfer, where I want to send an array to SPI function and it should receive a pointer to an array and the number of elements. I tried to modify and add another function but it's not working.

 

 

void SPI_TX_m16(uint16_t *data, uint8_t count)
{
  for (i=0;i<count;i++)
  {
    SPDR = *data>>8;
    while(!(SPSR & (1<<SPIF)));
    SPDR = *data;
    while(!(SPSR & (1<<SPIF)));
    *data--;
  }
}

void draw(void)
{
  uint8_t p=3,cascade_data[4]={0x00,0x00,0x01,0x04}; 
    for (row=1;row<9;row++)
    {
      PORTB &= ~(1<<PB2);
      SPI_TX_m16(data = (row<<8) | (cascade_data[p]),4);
      PORTB |= (1<<PB2);
    }
    _delay_ms(200); 
}

I want to pass the last element of the array from `draw();` function and the SPI transfer function should receive the last 16-bit pointer and decrement accordingly. Would SPI work with arrays?

 

The array above is an example, my main goal is to pass a pointer to Alphabet array to display letters on the matrix module:

 

 

uint8_t Alphabet[208]=
{
 0x00, 0x7f, 0x84, 0x84, 0x84, 0x84, 0x7f, 0x00,  // A
 0x00, 0xff, 0x91, 0x91, 0x91, 0x91, 0x6e, 0x00,  // B
 0x00, 0x7e, 0x81, 0x81, 0x81, 0x81, 0x42, 0x00,  // C
 0x00, 0xff, 0x81, 0x81, 0x81, 0x81, 0x7e, 0x00,  // D
 0x00, 0xff, 0x91, 0x91, 0x91, 0x91, 0x91, 0x00,  // E
 0x00, 0xff, 0x90, 0x90, 0x90, 0x90, 0x80, 0x00,  // F
 0x00, 0x7e, 0x81, 0x81, 0x89, 0x89, 0x4e, 0x00,  // G
 0x00, 0xff, 0x10, 0x10, 0x10, 0x10, 0xff, 0x00,  // H
 0x00, 0x00, 0x00, 0x81, 0xff, 0x81, 0x00, 0x00,  // I
 0x00, 0x00, 0x06, 0x01, 0x81, 0xfe, 0x80, 0x00,  // J
 0x00, 0x81, 0xff, 0x99, 0x24, 0xc3, 0x81, 0x00,  // K
 0x00, 0x81, 0xff, 0x81, 0x01, 0x01, 0x03, 0x00,  // L
 0x00, 0xff, 0x60, 0x18, 0x18, 0x60, 0xff, 0x00,  // M
 0x00, 0xff, 0x60, 0x10, 0x08, 0x06, 0xff, 0x00,  // N
 0x00, 0x7e, 0x81, 0x81, 0x81, 0x81, 0x7e, 0x00,  // O
 0x00, 0x7f, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00,  // P
 0x00, 0x7e, 0x81, 0x85, 0x89, 0x87, 0x7f, 0x00,  // Q
 0x00, 0xff, 0x98, 0x98, 0x94, 0x93, 0x61, 0x00,  // R
 0x00, 0x62, 0x91, 0x91, 0x91, 0x91, 0x4e, 0x00,  // S
 0x00, 0xc0, 0x81, 0xff, 0xff, 0x81, 0xc0, 0x00,  // T
 0x00, 0xfe, 0x01, 0x01, 0x01, 0x01, 0xfe, 0x00,  // U
 0x00, 0xfc, 0x02, 0x01, 0x01, 0x02, 0xfc, 0x00,  // V
 0x00, 0xff, 0x02, 0x04, 0x04, 0x02, 0xff, 0x00,  // W
 0x00, 0xc3, 0x24, 0x1c, 0x1c, 0x24, 0xc3, 0x00,  // X
 0x00, 0xc0, 0x20, 0x1f, 0x1f, 0x20, 0xc0, 0x00,  // Y
 0x00, 0xc3, 0x85, 0x8d, 0x91, 0xa1, 0xc3, 0x00,  // Z
 };

 

Last Edited: Thu. Jan 18, 2018 - 02:35 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Does your draw() function even compile? You’re doing some real strange stuff with the pointer address that doesn’t make sense to me. Why | row<<8??
Sit down and sketch the operations you want to perform step by step. The code should jump out at you.

Last Edited: Thu. Jan 18, 2018 - 03:57 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

wolfrose wrote:
Problem solved.

So mark the solution - instructions here: https://www.avrfreaks.net/comment...

 

But I have another question:

So start a new topic!

 

New question = New thread.

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes I know how to mark it as a solution. I don't want to bother people here, I wanted to extend he problem with the solution I got and the new problem came to me as a progress.

 

But, if this one considered as a new problem it doesn't matter if it's related, then OK starting a new topic is absolutely better.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
SPI_TX_m16(data = (row<<8) | (cascade_data[p]),4);

I want to send 16-bit data, row is the high byte to scan LED matrix rows ORing it with low byte which is the data, I developed this function to send 16-bit in one line.

 

Instead of the old one:

 

PORTB &= ~(1<<PB2);
SPI_TX(row);
SPI_TX(col);
PORTB |= (1<<PB2);

But I developed it to this arrangement:

SPI_TX(data = (row<<8) | col);

Where data is a 16-bit variable.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Solved the problem with these functions and this letters array smiley

 

 

uint8_t Alphabet[208]=
{
0x42, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x7e, 0x0, //A
0x3e, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x3e, 0x0, //B
0x3c, 0x42, 0x2, 0x2, 0x2, 0x42, 0x3c, 0x0    ,//C
0x3e, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3e, 0x0, //D
0x7e, 0x2, 0x2, 0x7e, 0x2, 0x2, 0x7e, 0x0     ,//E
0x2, 0x2, 0x2, 0x3e, 0x2, 0x2, 0x7e, 0x0,      //F
0x3c, 0x42, 0x62, 0x2, 0x2, 0x42, 0x3c, 0x0,   //G
0x42, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42, 0x0, //H
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x0, //I
0x18, 0x24, 0x20, 0x20, 0x20, 0x20, 0x70, 0x0, //J
0x22, 0x12, 0xa, 0x6, 0xa, 0x12, 0x22, 0x0,    //K
0x7e, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x0,       //L
0x41, 0x41, 0x41, 0x49, 0x55, 0x63, 0x41, 0x0, //M
0x41, 0x61, 0x51, 0x49, 0x45, 0x43, 0x41, 0x0, //N
0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x0, //O
0x2, 0x2, 0x2, 0x3e, 0x42, 0x42, 0x3e, 0x0,    //P
0xbc, 0x62, 0x52, 0x42, 0x42, 0x42, 0x3c, 0x0,//Q
0x62, 0x12, 0xa, 0x3e, 0x42, 0x42, 0x3c, 0x0,  //R
0x1c, 0x22, 0x4, 0x8, 0x10, 0x22, 0x1c, 0x0,   //S
0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x3e, 0x0,       //T
0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x0, //U
0x8, 0x14, 0x22, 0x41, 0x41, 0x41, 0x41, 0x0,  //V
0x63, 0x55, 0x49, 0x41, 0x41, 0x41, 0x41, 0x0, //W
0x41, 0x22, 0x14, 0x8, 0x14, 0x22, 0x41, 0x0,  //X
0x8, 0x8, 0x8, 0x8, 0x14, 0x22, 0x41, 0x0,     //Y
0x3e, 0x2, 0x4, 0x8, 0x10, 0x20, 0x3e, 0x0    //Z
 };

void SPI_TX_m16(uint16_t data)
{
    SPDR = data>>8;
    while(!(SPSR & (1<<SPIF)));
    SPDR = data;
    while(!(SPSR & (1<<SPIF))); 
}
void draw(void)
{
  uint8_t p,s=0,l;
  for (l=0;l<26;l++)            // to print 26 letters
  {       
    for (row=1;row<9;row++)     // for 8 matrix rows
    {
      PORTB &= ~(1<<PB2);
        for (p=0;p<4;p++)       // for 4 matrix devices
        {
          SPI_TX_m16(data = (row<<8) | (Alphabet[s]));
        }       
      PORTB |= (1<<PB2);
      s++;
    }
      _delay_ms(500);
  }
   
}

Last Edited: Sat. Jan 20, 2018 - 07:34 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

wolfrose wrote:
Solved the problem

So mark the solution - instructions here: https://www.avrfreaks.net/comment...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...