/74HC595

Shift Register interfacing library

Primary LanguageCMakeMIT LicenseMIT

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

image

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

  1. Start project with STM32CubeMX:
  2. Select: Project Manager -> Advanced Settings -> SPI -> LL
  3. Generate Code
  4. 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
  1. Then Build -> Clean -> Rebuild Project

Wiring

  • image
  • image
  • image

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);
    }
}