STM32 CAN Bus Examples
Complete STM32 code examples for UIROBOT products — CAN bus control (via SN65HVD230) and pulse-direction control (UIM344). Includes Keil uVision5 setup, wiring, and code.
This page provides complete **STM32F103C8T6** microcontroller example projects for controlling UIROBOT motors via **CAN bus** (using SN65HVD230) and **direct pulse-direction wiring**.
---
## Quick Selection
| Connection Method | Compatible Products | Docs |
|-----------------|-------------------|------|
| **STM32 + SN65HVD230 → CAN Bus** | UIM342 (single motor) | [AN250908] |
| **STM32 + SN65HVD230 → CAN Bus** | UIM342 (change Node ID) | [AN250909] |
| **STM32 + SN65HVD230 → CAN Bus** | UIM342 (multiple motors) | [AN250910] |
| **STM32 Direct Wiring (Pulse-Direction)** | UIM344 (single motor) | [AN250912] |
| **STM32 Direct Wiring (Pulse-Direction)** | UIM344 (high speed) | [AN250913] |
| **STM32 Direct Wiring (Pulse-Direction)** | UIM344 (multiple motors) | [AN250914] |
---
## Section 1: STM32 + SN65HVD230 → CAN Bus (UIM342)
### Background
The UIM342 is a high-performance integrated stepper motor driver designed for applications requiring precise motion control. By combining an **STM32F103C8T6** microcontroller, the **SN65HVD230** CAN transceiver, and **UIM342** motor drivers, users can efficiently create a powerful motion control system. This section provides step-by-step instructions for controlling UIM342 using STM32F103C8T6 and SN65HVD230.
### Required Hardware
| Item | Qty | Description |
|------|:---:|-------------|
| STM32F103C8T6 Board | 1 | "Blue Pill" development board |
| SN65HVD230 | 1 | CAN transceiver module |
| UIM342 Series Motor | 1+ | CAN bus smart motor |
| ST-LINK V2 | 1 | Debugger/programmer |
| 24V DC Power Supply | 1 | For motor power |
| Keil uVision5 | 1 | IDE (install on PC) |
### Wiring

### Debugger Connections
| STM32F103C8T6 | ST-LINK V2 |
|---------------|------------|
| SWDIO | SWDIO |
| SWCLK | SWCLK |
| GND | GND |
| 3.3V (optional) | 3.3V |
---
## Section 2: STM32 Direct Wiring — Pulse-Direction (UIM344)
### Background
The UIM344 is a closed-loop stepper motor driver that accepts standard pulse-direction signals. Connect STM32 GPIO pins directly to the motor's PLS (Pulse), DIR (Direction), and ENA (Enable) inputs — no CAN transceiver required.
### Required Hardware
| Item | Qty | Description |
|------|:---:|-------------|
| STM32F103C8T6 Board | 1 | "Blue Pill" development board |
| UIM344 Series Motor | 1+ | Pulse-direction stepper motor |
| ST-LINK V2 | 1 | Debugger/programmer |
| 24V DC Power Supply | 1 | For motor power |
| Keil uVision5 | 1 | IDE |
### Wiring
```
STM32F103C8T6 UIM344 Motor
+----------------+ +--------------+
| GPIO Pin |------>| PLS (Pulse) |
| GPIO Pin |------>| DIR (Dir.) |
| GPIO Pin |------>| ENA (Enable) |
| GND |------>| GND |
+----------------+ +--------------+
|
24V DC Power Supply
```
> **Note**: For multi-motor control, connect each motor's PLS/DIR/ENA to separate STM32 GPIO pins.
---
## Sample Code
### Download Links
| Application Note | Description | Download |
|-----------------|-------------|----------|
| AN250908 | UIM342 basic CAN control | [Download](https://www.uirobot.com/uploads/files/Stm32_C_UIM342_AN250908.zip) |
| AN250909 | UIM342 change Node ID | [Download](https://www.uirobot.com/uploads/files/Stm32_C_UIM342_ChangeNodeID_AN250909.zip) |
| AN250910 | UIM342 multi-motor CAN control | [Download](https://www.uirobot.com/uploads/files/Stm32_C_UIM342_Multiple_AN250910.zip) |
| AN250912 | UIM344 basic pulse-direction | [Download](https://www.uirobot.com/uploads/files/Stm32_C_UIM344_AN250912.zip) |
| AN250913 | UIM344 high-speed pulse-direction | [Download](https://www.uirobot.com/uploads/files/Stm32_C_UIM344_HighSpeed_AN250913.zip) |
| AN250914 | UIM344 multi-motor pulse-direction | [Download](https://www.uirobot.com/uploads/files/Stm32_C_UIM344_Multiple_AN250914.zip) |
> **Note**: The actual sample code is provided in the ZIP files above. The code snippet illustrates the general structure.
---
## Step-by-Step Setup
### Step 1 — Install Keil uVision5
1. Visit the official Keil website: [keil.com](https://www.keil.com/)
2. Navigate to **Downloads → Product Downloads → MDK Arm**
3. Download and install Keil uVision5 (including STM32F1 device support)
### Step 2 — Download Sample Code
1. Visit [uirobot.com](https://uirobot.com)
2. Navigate to **Support → Code Example**
3. Find the STM32 section and download the appropriate sample code
4. Extract the downloaded ZIP file
### Step 3 — Install ST-LINK V2 Driver
1. Connect ST-LINK V2 to your PC via USB
2. Install the ST-LINK V2 driver (included in Keil installation or available from STMicroelectronics)
3. Verify the driver is installed correctly in Device Manager
### Step 4 — Configure Keil Project
1. Open the `.uvprojx` project file in Keil uVision5
2. Select **Project → Options for Target**
3. In the **Device** tab, verify STM32F103C8 is selected
4. In the **C/C++** tab, set **Compiler version 5** (or as required)
5. In the **Output** tab, check **"Create HEX File"**
6. In the **Debug** tab, select **ST-Link Debugger**
### Step 5 — Compile and Debug
1. Click **Build** (or press F7) to compile the project
2. Confirm no errors in the build output
3. Connect ST-LINK V2 to the STM32 board (SWDIO, SWCLK, GND)
4. Click **Download** to program the microcontroller
5. Click **Start/Stop Debug Session** to debug if needed
---
## Download All Sample Codes
| Application Note | Description | Download Link |
|-----------------|-------------|---------------|
| AN250908 | UIM342 basic CAN control | [Download ZIP](https://www.uirobot.com/uploads/files/Stm32_C_UIM342_AN250908.zip) |
| AN250909 | UIM342 change Node ID | [Download ZIP](https://www.uirobot.com/uploads/files/Stm32_C_UIM342_ChangeNodeID_AN250909.zip) |
| AN250910 | UIM342 multi-motor CAN control | [Download ZIP](https://www.uirobot.com/uploads/files/Stm32_C_UIM342_Multiple_AN250910.zip) |
| AN250912 | UIM344 basic pulse-direction | [Download ZIP](https://www.uirobot.com/uploads/files/Stm32_C_UIM344_AN250912.zip) |
| AN250913 | UIM344 high-speed pulse-direction | [Download ZIP](https://www.uirobot.com/uploads/files/Stm32_C_UIM344_HighSpeed_AN250913.zip) |
| AN250914 | UIM344 multi-motor pulse-direction | [Download ZIP](https://www.uirobot.com/uploads/files/Stm32_C_UIM344_Multiple_AN250914.zip) |
---
## Related Documents
- [UIROBOT Code Examples Overview](/docs/code-examples-overview)
- [Arduino CAN Bus Examples](/docs/arduino-examples)
- [Raspberry Pi 4 CAN Bus Examples](/docs/raspberry-pi-examples)
- [STC89C52 CAN Bus Examples](/docs/stc89c52-examples)
- [UIM342 CAN Bus Motor Controller](/docs/uim342)
- [UIM344 Pulse-Direction Motor Controller](/docs/uim344)
- [Quick Start Guide](/docs/quick-start)
---
*Last updated: 2026-06-25 | Based on Application Notes AN250908-AN250914*