1

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!

luka032
  • 925
  • 4
  • 12
  • 34
  • Sounds like you need to read the datasheet for that display. If you send nothing but the "turn all the LEDs on" command repeatedly every half a second, it shouldn't come as too much of a surprise that all the LEDs are on... – Notlikethat Dec 14 '16 at 10:30

1 Answers1

1

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
}
luka032
  • 925
  • 4
  • 12
  • 34