This project integrates the STM32 microcontroller with the 74HC595 shift register to build an LED bar-graph display system. By leveraging the STM32’s SPI interface and GPIO control, the microcontroller efficiently manages the 74HC595 to drive a sequence of LEDs configured as a bar graph.
Exploring the 74HC595 Shift Register
The 74HC595 is an 8-bit serial-in, parallel-out shift register with a storage register and 3-state outputs. It allows STM32 to send data serially and expand GPIO pins, making it well-suited for controlling multiple LEDs in bar-graph or display applications.
In this project, each of the 74HC595 outputs is connected to an LED. By clocking data into the shift register and toggling the latch pin, the STM32 updates the bar-graph LEDs to display levels or patterns.
STM32CubeMX Setup- MCU Selection: STM32F103C6 (8MHz clock)
- SPI1 Configuration:
-
Mode: Master Transmit Only
-
Data Size: 8-bit
-
MSB First
-
Baud Rate Prescaler: 32 (≈250kHz)
-
CPOL = Low, CPHA = 1Edge
- GPIO Configuration:
-
PA4 → Output (Latch Pin)
-
SPI1 Pins (PA5 = SCK, PA7 = MOSI)
- Generate code in STM32CubeIDE.
Key Functions
- Shift Register Write Function
-
void Write_74HC595(uint8_t data);
- Bar Graph Patterns
-
const uint8_t patterns[10] = {0x01,0x03,0x07,0x0F,0x1F,0x3F,0x7F,0xFF,0xAA,0x55};
- Main Loop Example
for (int i = 0; i < 10; i++) {
Write_74HC595(patterns[i]);
HAL_Delay(500);
}
Components
- STM32F103C6
- 74HC595 Shift Register
- LED Bar Graph (8 LEDs)
- Virtual Terminal (optional for debugging via UART)
Connections
- PA5 → SRCLK (Shift Clock)
- PA7 → SER (Data)
- PA4 → RCLK (Latch)
- LEDs → 74HC595 Q0–Q7 outputs
Simulation Steps
- Load the .hex file into STM32.
- Run simulation.
- Observe LED bar-graph animations according to programmed patterns.
If you have any questions or suggestions don't hesitate to leave a comment below
Comments