This project demonstrates how to use the SPI protocol to control Matrix LED 8x8 and 7-Segment displays using the MAX7219 display driver IC with an STM32 microcontroller. The MAX7219 simplifies control by handling multiplexing and driving for up to 8 digits of 7-segment displays or a grid of 64 LEDs, receiving data via SPI from the STM32 master. The project covers initializing the MAX7219, sending data to display patterns or numbers, and managing display properties like intensity.
STM32CubeMX Configuration- Create a new STM32F103C6 project.
- Set the system clock to 8 MHz.
- Configure SPI1 and SPI2 in Transmit Only Master mode.
- GPIO Configuration:
- PA4 configured as GPIO Output (Primary Chip Select for MAX7219).
- PB0 configured as GPIO Output (Control signal for Matrix display selection).
- PB12 configured as GPIO Output (Secondary Chip Select for 7-Segment display).
- Generate initialization code.
- Open the generated project.
- Create Driver Files: Add max7219.h and max7219.c.
- Implement Core MAX7219 Functions:
- max7219_Init():
Configures MAX7219 registers for shutdown, decode mode, intensity, scan limit, and display test.
- max7219_SendData(uint8_t reg, uint8_t data):
Sends a command (register address + data) to the MAX7219 via SPI.
- max7219_SetIntensity(uint8_t intensity):
Sets display brightness.
- max7219_Clear():
Clears all digits or LEDs.
- max7219_TurnOn()/TurnOff():
Controls shutdown mode.
- Application Logic (main.c):
- Initialize SPI and GPIO pins.
- Call max7219_Init() to set up the display.
- Use max7219_SendData() to send digit data for 7-segment displays or row data for Matrix LED patterns.
- Build the project.
- Add STM32F103C6, MAX7219, MATRIX-8X8-RED, and 7SEG-MPX8-CC-BLUE components.
- Wiring:
- Connect STM32 SPI pins (SCK, MOSI) to MAX7219 (CLK, DIN).
- Connect STM32 GPIO pins (PA4, PB12) to MAX7219 LOAD (CS) pins.
- Connect MAX7219 segment outputs to 7-segment display pins.
- Connect MAX7219 digit outputs to matrix rows/columns.
- Load the compiled .hex file into the MCU.
- Start simulation and test display output.
If you have any questions or suggestions don't hesitate to leave a comment below
Comments