STM32 Library Collection

STM32 and MAX7219 LED Matrix Guide

Connect a MAX7219 LED matrix to STM32, configure HAL SPI, and show your first frame with the AndiArvy library.

Wire one module first

Connect SPI MOSI to DIN, SCK to CLK, and an output GPIO to LOAD/CS. Share ground between the STM32 and display supply. The MAX7219 uses a 5 V supply and specifies a minimum input-high voltage of 3.5 V. Use a suitable 3.3 V to 5 V logic buffer for MOSI, SCK, and LOAD when using 3.3 V STM32 outputs.

Configure SPI in STM32CubeMX

Use master mode, MSB first, software NSS, and SPI mode 0. The driver accepts 8-bit or 16-bit words. Keep SCK within the 10 MHz device limit and start slower during bring-up. Set the LOAD GPIO high initially. On the supplied demo board, SPI1 uses PA5 for SCK, PA7 for MOSI, and PA4 for LOAD.

Draw and send the first frame

Compile MAX7219.c and fonts.c and add Core/Inc to your include path. Create a display handle and a MAX7219_Config with your initialized SPI handle, LOAD port and pin, module count, and orientation. Call this helper after the HAL, clocks, GPIO, and SPI are initialized. Drawing changes the framebuffer. Update sends it to the matrix.

#include "MAX7219.h"

HAL_StatusTypeDef ShowFirstPixel(MAX7219_HandleTypeDef *display,
                                const MAX7219_Config *config)
{
    HAL_StatusTypeDef status = MAX7219_Init(display, config);
    if (status != HAL_OK) {
        return status;
    }

    MAX7219_SetPixel(display, 0, 0, true);
    return MAX7219_Update(display);
}

Check wiring, then adjust orientation

If the matrix stays blank, check the supply, shared ground, logic levels, and LOAD rising edge with a scope or logic analyzer. If the pixel appears in the wrong corner, adjust the orientation. Once one module works, connect each DOUT to the next DIN, share CLK and LOAD, and update the configured module count to match the chain.