Max7219 (8x8 Dot Matrix LED Driver) on attiny

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

Hello,

 

i´ve tried to connect an 8x8 Dot Matrix with an attiny and found some information on the net, but unfortunately they always used some unos or something, but i should not be a big deal in connecting an attiny with a Max7219. 

i tried that but, as simple as this task is, i have no luck. I use pins 5,6 and 7 (PB0, PB1 and PB2) for DIN (din) , load (CS) and clock (CLK) for the Driver, but the led dot matrix is only displaying rubbish, so i thing, that i connected it somehow in a wrong way but there are not so many options to connect it wrong. Maybe i overlocked something fundamental, is there someone who already connect a Max7219 Driver to an attiny(45)?

 

regards

regards

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

You can write to a MAX7219 with regular SPI.    Each transaction is 16-bits.    i.e. two 8-bit SPI

You do a CS_lo(),  spi(cmd), spi(dat), CS_hi()

 

You can use the USI to implement the SPI,   or simply bit-bang.

 

There are many examples.    My advice is to always finish with the CS_hi()

You will see some people do spi(cmd), spi(dat), CS_hi(), CS_lo().    This is extremely prone to noise and glitches.    It also means that you can only have one device on the SPI bus.

 

The biggest source of confusion is because the /CS pin is called LOAD.

 

David.

Last Edited: Fri. Jan 9, 2015 - 10:05 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I found a short example that uses bit-banged SPI:

/*
  One MAX7219 connected to an 8x8 LED matrix.
 */

#include <avr/io.h>
#include <util/delay.h>

#define CLK_HIGH()  PORTB |= (1<<PB2)
#define CLK_LOW()   PORTB &= ~(1<<PB2)
#define CS_HIGH()   PORTB |= (1<<PB1)
#define CS_LOW()    PORTB &= ~(1<<PB1)
#define DATA_HIGH() PORTB |= (1<<PB0)
#define DATA_LOW()  PORTB &= ~(1<<PB0)
#define INIT_PORT() DDRB |= (1<<PB0) | (1<<PB1) | (1<<PB2)

const __flash uint8_t smile[8] = {
        0b00000000,
        0b01100110,
        0b01100110,
        0b00011000,
        0b00011000,
        0b10000001,
        0b01000010,
        0b00111100};

const __flash uint8_t sad[8] = {
        0b00000000,
        0b01100110,
        0b01100110,
        0b00011000,
        0b00011000,
        0b00000000,
        0b00111100,
        0b01000010,
};


void spi_send(uint8_t data)
{
    uint8_t i;

    for (i = 0; i < 8; i++, data <<= 1)
    {
	CLK_LOW();
	if (data & 0x80)
	    DATA_HIGH();
	else
	    DATA_LOW();
	CLK_HIGH();
    }
    
}

void max7219_writec(uint8_t high_byte, uint8_t low_byte)
{
    CS_LOW();
    spi_send(high_byte);
    spi_send(low_byte);
    CS_HIGH();
}

void max7219_clear(void)
{
    uint8_t i;
    for (i = 0; i < 8; i++)
    {
	max7219_writec(i+1, 0);
    }
}

void max7219_init(void)
{
    INIT_PORT();
    // Decode mode: none
    max7219_writec(0x09, 0);
    // Intensity: 3 (0-15)
    max7219_writec(0x0A, 1);
    // Scan limit: All "digits" (rows) on
    max7219_writec(0x0B, 7);
    // Shutdown register: Display on
    max7219_writec(0x0C, 1);
    // Display test: off
    max7219_writec(0x0F, 0);
    max7219_clear();
}


uint8_t display[8];

void update_display(void)
{
    uint8_t i;

    for (i = 0; i < 8; i++)
    {
	max7219_writec(i+1, display[i]);
    }
}

void image(const __flash uint8_t im[8])
{
    uint8_t i;

    for (i = 0; i < 8; i++)
	display[i] = im[i];
}

void set_pixel(uint8_t r, uint8_t c, uint8_t value)
{
    switch (value)
    {
    case 0: // Clear bit
	display[r] &= (uint8_t) ~(0x80 >> c);
	break;
    case 1: // Set bit
	display[r] |= (0x80 >> c);
	break;
    default: // XOR bit
	display[r] ^= (0x80 >> c);
	break;
    }
}


int main(void)
{
    uint8_t i;
    
    max7219_init();
    
    while(1)
    {
	image(sad);
	update_display();
	_delay_ms(500);
	image(smile);
	update_display();
	_delay_ms(500);

	// Invert display
	for (i = 0 ; i < 8*8; i++)
	{
	    set_pixel(i / 8, i % 8, 2);
	    update_display();
	    _delay_ms(10);
	}
	_delay_ms(500);
    }
}

 

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

Hello,

 

@snigelen, thank you very much!

While i can compile and upload your example, it ran one time and then it showed a very abitrary lightship, but i couldn't recognize any sign or the smile or the sad face. Every time i connect the 5v it has an other behavior. Maybe there is something fundamental missing, but when i make for example a light program to light up different led´s, powere by PB0...PB3, then it is functioning correctly. It is a mystery.

 

regards 

 

 

 

 

regards

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

Do you have bypass capacitators on the AVR and max chip? We had a similar problem recently.

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

Hello,

 

i checked my circuit, and now, maybe there were loose cables, there is an constant behavior, but only all led are burning, because of the vcc the matrix is now receiving.

I am going mad, so i checked the signals and on the DIN Port (PB0) it seems, as if there is no relevant signal, the max amplitude which is seen on the oscilloscope is 16mV, so there is no signal at all on DIN, and i guess, there should be a lot of data traffic.

I wonder, what is going wrong.

 

regards

regards

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

That sounds like you have some bad connections. I tested it on a tiny85 @8MHz and a max7219 module like this

http://www.ebay.com/itm/MAX7219-Dot-Display-Module-Matrix-Module-Cascade-Control-DIY-/221654163632?pt=LH_DefaultDomain_0&hash=item339b9e20b0

and it worked fine.

Last Edited: Fri. Jan 9, 2015 - 12:36 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@cartman,

 

i bought this one: http://www.ebay.de/itm/271520271983?_trksid=p2059210.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

i have nothing else between attiny85 and the Max7219.

regards

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

@sniglen,

 

but the one, you are showing there, has no Max7219, has it?

regards

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

Maybe you have put the max or the display 180 degrees wrong?

 

Edit:

Quote:
but the one, you are showing there, has no Max7219, has it?

Yes it has one, you can see it in the image.

Last Edited: Fri. Jan 9, 2015 - 12:39 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I already though of it, that the max is put in in the wrong direction, but i bought it as it was assembled.

regards

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

On my plate, there is no capacitor, although, it is printed on the plate that there should be two capacitors, one with 10 and one with 0,1 uF.  

I soldered them but no luck, this board is somehow faulty, i think. 

But now i can see the output of DIN (PB0), it has 4,88 Vpp, as aspected, but the led matrix is not working.

 

regards

regards