Advanced 256 microsteps integrated motor driver with step-clock and direction interface
A
A
Hardware Overview
How does it work?
STSPIN820 Click is based on the STSPIN820, an advanced stepper motor driver from STMicroelectronics. The monolithic IC incorporates both the power MOSFETs and the logic circuitry necessary for simplified control and reliable functioning of the connected bipolar stepper motor. Featuring a microstepping sequencer that supports up to 256 microsteps, this IC can perform very smooth and silent movements. The step sequencer also controls the VREF voltage, allowing the current through coils to be optimal during the microstepping. In full-step mode, the maximum current through the coils is controlled by the VREF. As the sequencer propagates through the microsteps, the VREF is further reduced following a circular pattern, ensuring maximum power efficiency for each step. The STSPIN820 has two PWM current controllers with a fixed OFF time for each H-Bridge, during which the current decay sequence is performed. This effectively limits the maximum current through the connected motor phase. The OFF (decay) time is approximately 25 µs on this Click board™. The DECAY pin determines the decay mode. In mixed decay mode (DECAY pin at the LOW logic level), the decay period is divided into slow-decaying and
fast-decaying segments. The slow decay segment lasts 5/8 of the total OFF time, while the fast decay segment lasts 3/8 of the total OFF time. When the DECAY pin is at the HIGH logic level, the slow decay mode lasts for the entire OFF time. The PWM current controller compares the voltage across two sense resistors (VSENS1 and VSENS2) and the VREF voltage, which a potentiometer can adjust. When VSENS exceeds the VREF voltage, the current limiting is triggered, and the OFF timer starts counting. The STSPIN820 contains two independent H-Bridges, each controlling one phase of the bipolar stepper motor. The motor can be controlled by using these pins: DIR, STCK, RST, EN, and FAULT. The DIR pin determines the direction of the rotation. If set to a HIGH logic level, the internal microstepping counter will increase its value with each pulse coming through the STCK pin. The LOW logic level on this pin will cause the microstepping sequencer to decrease its counter. DIR pin is routed both to the mikroBUS™ pin AN (labeled as DIR). SW1, SW2, and SW3 switches on the Click board™ are used to determine the step size. They have MODE 1, MODE 2, and MODE 3 pins routed to them, respectively. All these switches can set the mode at any moment during the
operation. The STBY/RESET (RST) pin of the STSPIN820 is used to set both bridge outputs in HIGH-Z mode, disconnecting the power supply from the H-Bridges. This pin allows lower average power consumption as no current can flow from the power supply to the motor. This pin is routed to the RST pin of the mikroBUS™. The control logic circuitry will be reset when the standby mode is left. The EN/FAULT (EN) pin has a double purpose: when set to a high logic level, it acts as a chip enable, allowing the device to operate. In the case of a fault condition on the IC, it will be asserted to a LOW logic level, acting as an interrupt pin. A restart attempt will be made after a timeout period defined by the external capacitor and resistor values. This pin is routed to both the CS and INT pins of the mikroBUS™, allowing the host MCU to use both functions. These pins are labeled EN and FLT on the Click board™, respectively. The motor power supply can be connected to the input terminal labeled as VIN and should be within the range of 7V to 45V. Stepper motor coils can be connected to A1, B2, B1, and A2 terminals. The Click board™ requires an external power supply for the motor to work. However, it also requires 3.3V from the mikroBUS™ rail.
Features overview
Development board
Nucleo-64 with STM32F091RC MCU offers a cost-effective and adaptable platform for developers to explore new ideas and prototype their designs. This board harnesses the versatility of the STM32 microcontroller, enabling users to select the optimal balance of performance and power consumption for their projects. It accommodates the STM32 microcontroller in the LQFP64 package and includes essential components such as a user LED, which doubles as an ARDUINO® signal, alongside user and reset push-buttons, and a 32.768kHz crystal oscillator for precise timing operations. Designed with expansion and flexibility in mind, the Nucleo-64 board features an ARDUINO® Uno V3 expansion connector and ST morpho extension pin
headers, granting complete access to the STM32's I/Os for comprehensive project integration. Power supply options are adaptable, supporting ST-LINK USB VBUS or external power sources, ensuring adaptability in various development environments. The board also has an on-board ST-LINK debugger/programmer with USB re-enumeration capability, simplifying the programming and debugging process. Moreover, the board is designed to simplify advanced development with its external SMPS for efficient Vcore logic supply, support for USB Device full speed or USB SNK/UFP full speed, and built-in cryptographic features, enhancing both the power efficiency and security of projects. Additional connectivity is
provided through dedicated connectors for external SMPS experimentation, a USB connector for the ST-LINK, and a MIPI® debug connector, expanding the possibilities for hardware interfacing and experimentation. Developers will find extensive support through comprehensive free software libraries and examples, courtesy of the STM32Cube MCU Package. This, combined with compatibility with a wide array of Integrated Development Environments (IDEs), including IAR Embedded Workbench®, MDK-ARM, and STM32CubeIDE, ensures a smooth and efficient development experience, allowing users to fully leverage the capabilities of the Nucleo-64 board in their projects.
Microcontroller Overview
MCU Card / MCU

Architecture
ARM Cortex-M0
MCU Memory (KB)
256
Silicon Vendor
STMicroelectronics
Pin count
64
RAM (Bytes)
32768
You complete me!
Accessories
Click Shield for Nucleo-64 comes equipped with two proprietary mikroBUS™ sockets, allowing all the Click board™ devices to be interfaced with the STM32 Nucleo-64 board with no effort. This way, Mikroe allows its users to add any functionality from our ever-growing range of Click boards™, such as WiFi, GSM, GPS, Bluetooth, ZigBee, environmental sensors, LEDs, speech recognition, motor control, movement sensors, and many more. More than 1537 Click boards™, which can be stacked and integrated, are at your disposal. The STM32 Nucleo-64 boards are based on the microcontrollers in 64-pin packages, a 32-bit MCU with an ARM Cortex M4 processor operating at 84MHz, 512Kb Flash, and 96KB SRAM, divided into two regions where the top section represents the ST-Link/V2 debugger and programmer while the bottom section of the board is an actual development board. These boards are controlled and powered conveniently through a USB connection to program and efficiently debug the Nucleo-64 board out of the box, with an additional USB cable connected to the USB mini port on the board. Most of the STM32 microcontroller pins are brought to the IO pins on the left and right edge of the board, which are then connected to two existing mikroBUS™ sockets. This Click Shield also has several switches that perform functions such as selecting the logic levels of analog signals on mikroBUS™ sockets and selecting logic voltage levels of the mikroBUS™ sockets themselves. Besides, the user is offered the possibility of using any Click board™ with the help of existing bidirectional level-shifting voltage translators, regardless of whether the Click board™ operates at a 3.3V or 5V logic voltage level. Once you connect the STM32 Nucleo-64 board with our Click Shield for Nucleo-64, you can access hundreds of Click boards™, working with 3.3V or 5V logic voltage levels.
The 28BYJ-48 is an adaptable 5VDC stepper motor with a compact design, ideal for various applications. It features four phases, a speed variation ratio of 1/64, and a stride angle of 5.625°/64 steps, allowing precise control. The motor operates at a frequency of 100Hz and has a DC resistance of 50Ω ±7% at 25°C. It boasts an idle in-traction frequency greater than 600Hz and an idle out-traction frequency exceeding 1000Hz, ensuring reliability in different scenarios. With a self-positioning torque and in-traction torque both exceeding 34.3mN.m at 120Hz, the 28BYJ-48 offers robust performance. Its friction torque ranges from 600 to 1200 gf.cm, while the pull-in torque is 300 gf.cm. This motor makes a reliable and efficient choice for your stepper motor needs.
Used MCU Pins
mikroBUS™ mapper
Take a closer look
Click board™ Schematic

Step by step
Project assembly
Track your results in real time
Application Output
1. Application Output - In Debug mode, the 'Application Output' window enables real-time data monitoring, offering direct insight into execution results. Ensure proper data display by configuring the environment correctly using the provided tutorial.

2. UART Terminal - Use the UART Terminal to monitor data transmission via a USB to UART converter, allowing direct communication between the Click board™ and your development system. Configure the baud rate and other serial settings according to your project's requirements to ensure proper functionality. For step-by-step setup instructions, refer to the provided tutorial.

3. Plot Output - The Plot feature offers a powerful way to visualize real-time sensor data, enabling trend analysis, debugging, and comparison of multiple data points. To set it up correctly, follow the provided tutorial, which includes a step-by-step example of using the Plot feature to display Click board™ readings. To use the Plot feature in your code, use the function: plot(*insert_graph_name*, variable_name);. This is a general format, and it is up to the user to replace 'insert_graph_name' with the actual graph name and 'variable_name' with the parameter to be displayed.

Software Support
Library Description
This library contains API for STSPIN820 Click driver.
Key functions:
stspin820_set_direction
- This function sets the motor direction by setting the DIR pin logic statestspin820_drive_motor
- This function drives the motor for the specific number of steps at the selected speedstspin820_reset_device
- This function resets the device by toggling the RST pin
Open Source
Code example
The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.
/*!
* @file main.c
* @brief STSPIN820 Click Example.
*
* # Description
* This example demonstrates the use of the STSPIN820 click board by driving the
* motor in both directions for a desired number of steps.
*
* The demo application is composed of two sections :
*
* ## Application Init
* Initializes the driver and performs the click default configuration.
*
* ## Application Task
* Drives the motor clockwise for 200 steps and then counter-clockwise with a 2 seconds
* delay delay on driving mode change. All data is being logged on the USB UART where
* you can track the program flow.
*
* @author Stefan Filipovic
*
*/
#include "board.h"
#include "log.h"
#include "stspin820.h"
static stspin820_t stspin820; /**< STSPIN820 Click driver object. */
static log_t logger; /**< Logger object. */
void application_init ( void )
{
log_cfg_t log_cfg; /**< Logger config object. */
stspin820_cfg_t stspin820_cfg; /**< Click config object. */
/**
* Logger initialization.
* Default baud rate: 115200
* Default log level: LOG_LEVEL_DEBUG
* @note If USB_UART_RX and USB_UART_TX
* are defined as HAL_PIN_NC, you will
* need to define them manually for log to work.
* See @b LOG_MAP_USB_UART macro definition for detailed explanation.
*/
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
stspin820_cfg_setup( &stspin820_cfg );
STSPIN820_MAP_MIKROBUS( stspin820_cfg, MIKROBUS_1 );
if ( DIGITAL_OUT_UNSUPPORTED_PIN == stspin820_init( &stspin820, &stspin820_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
stspin820_default_cfg ( &stspin820 );
log_info( &logger, " Application Task " );
}
void application_task ( void )
{
log_printf ( &logger, " Move 200 steps clockwise, speed: slow\r\n\n" );
stspin820_set_direction ( &stspin820, STSPIN820_DIR_CW );
stspin820_drive_motor ( &stspin820, 200, STSPIN820_SPEED_SLOW );
Delay_ms ( 2000 );
log_printf ( &logger, " Move 200 steps counter-clockwise, speed: fast\r\n\n" );
stspin820_set_direction ( &stspin820, STSPIN820_DIR_CCW );
stspin820_drive_motor ( &stspin820, 200, STSPIN820_SPEED_FAST );
Delay_ms ( 2000 );
}
int main ( void )
{
application_init( );
for ( ; ; )
{
application_task( );
}
return 0;
}
// ------------------------------------------------------------------------ END