74HC595
STM32 LL(Low-Layer) shift register library. A shift register allows to expand the number of I/O pins you can use from any microcontroller.
Features
- No limit in register count
- Easy bit manipulation
- Small code footprint
Add as CPM project dependency
How to add CPM to the project, check the link
CPMAddPackage(
NAME 74HC595
GITHUB_REPOSITORY ximtech/74HC595
GIT_TAG origin/main)
Project configuration
- Start project with STM32CubeMX:
- Select: Project Manager -> Advanced Settings -> SPI -> LL
- Generate Code
- Add sources to project:
add_subdirectory(${STM32_CORE_SOURCE_DIR}/SPI/Polling) # add SPI to project
include_directories(${74HC595_DIRECTORY}) # source directories
file(GLOB_RECURSE SOURCES ${74HC595_SOURCES}) # source files
- Then Build -> Clean -> Rebuild Project
Wiring
Usage
#include "74HC595.h"
#define SHIFT_REGISTER_COUNT 2
#define DELAY 50
int main() {
ShiftRegister shiftRegister = initShiftRegister(SPI1, CHIP_SELECT_GPIO_Port, CHIP_SELECT_Pin, SHIFT_REGISTER_COUNT, REG_RESET_GPIO_Port, REG_RESET_Pin);
uint16_t binaryCounter = 0;
while (1) {
sendU16ToShiftRegister(&shiftRegister, binaryCounter);
latchShiftRegister(&shiftRegister);
binaryCounter++;
delay_ms(DELAY);
}
}