LED 8x8 Matrix with MAX7219 on ARM STM32 MikroC

2.2k views Asked by At

I would like to send some data to display it on LED 8x8 matrix which has MAX7219 chip on it.

My MCU is ARM STM32F4 and I'm using MikroC as develop tool to program this peripheral.

I am total beginner to this way of programming, so I would like to know how is sending text i.e. done from MCU to LED matrix.

I've wrote some code, and when I turn on my MCU all 64 LEDs are shining constantly, I don't have idea why.

// MCU's CS/PE11 pin
sbit Chip_Select at ODR11_GPIOE_ODR_bit;

void main() {
// Set PE11 as output pin (ChipSelect pin)
GPIO_Digital_Output(&GPIOE_BASE, _GPIO_PINMASK_11);

// Initialization method from SPI library from mikroC 
SPI2_Init();

  while (1) {
        // select led matrix
        Chip_Select = 0;

        // sending data to matrix
        SPI2_Write(0x01FF);

        // deselect led matrix
        Chip_Select = 1;
        Delay_ms(500);
  }
} 

Hope anyone could help me get more familiar with this.

Thanks in advance!

1

There are 1 answers

0
luka032 On BEST ANSWER

MAX7219 must be initialized before use. I forgot that, so this is my working code:

void max7219_init() {
GPIO_Digital_Output(&GPIOE_BASE, _GPIO_PINMASK_11);

Chip_Select2 = 0;               // SELECT MAX
SPI2_Write(0x09);               // No decoding
SPI2_Write(0x00);
Chip_Select2 = 1;               // DESELECT MAX

Chip_Select2 = 0;               // SELECT MAX
SPI2_Write(0x0A);
SPI2_Write(0x01);               // Segment luminosity intensity
Chip_Select2 = 1;               // DESELECT MAX

Chip_Select2 = 0;               // SELECT MAX
SPI2_Write(0x0B);
SPI2_Write(0x07);               // Display refresh
Chip_Select2 = 1;               // DESELECT MAX

Chip_Select2 = 0;               // SELECT MAX
SPI2_Write(0x0C);
SPI2_Write(0x01);               // Turn on the display
Chip_Select2 = 1;               // DESELECT MAX

Chip_Select2 = 0;               // SELECT MAX
SPI2_Write(0x00);
SPI2_Write(0xFF);               // No test
Chip_Select2 = 1;               // DESELECT MAX
}