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.
- No limit in register count
- Easy bit manipulation
- Small code footprint
How to add CPM to the project, check the link
CPMAddPackage(
NAME 74HC595
GITHUB_REPOSITORY ximtech/74HC595
GIT_TAG origin/main)
- 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
#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);
}
}