Tool/software:
Hello,
I’m trying to drive a bipolar stepper motor with a DRV8818 using STEP/DIR from an ESP32-C6-DevKitC-1. I’ve attached my schematic and can also share the minimal firmware if useful.
Setup
-
MCU / FW: ESP32-C6-DevKitC-1, PlatformIO (Espressif32 6.8.1), ESP-IDF 5.3.0, 3.3 V logic
-
Driver: TI DRV8818
-
VM (motor supply): 24V
-
Sense resistors: 0.10 Ω (per phase)
-
VREF measured: ~2.0 V → I_trip calc ≈ Vref / (8·Rsense) = 2.0 V / (8·0.10 Ω) ≈ 2.5 A
-
Decay: Mixed
-
Microstepping: USM0/USM1 both fixed to GND -> fullstep.
-
Control pins (default states):
-
ENABLEn: LOW (driver enabled)
-
SLEEPn: HIGH (awake)
-
RESETn: HIGH (held high)
-
STEP/DIR: from GPIO 18 and 19
-
Code:
#include <stdint.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "esp_rom_sys.h" // esp_rom_delay_us()
#define PIN_STEP 18
#define PIN_DIR 19
static inline void step_pulses(int steps, uint32_t half_period_us) {
for (int i = 0; i < steps; ++i) {
gpio_set_level(PIN_STEP, 1);
esp_rom_delay_us(half_period_us);
gpio_set_level(PIN_STEP, 0);
esp_rom_delay_us(half_period_us);
}
}
void app_main(void) {
// STEP & DIR als Outputs
gpio_config_t io = {
.pin_bit_mask = (1ULL << PIN_STEP) | (1ULL << PIN_DIR),
.mode = GPIO_MODE_OUTPUT,
.pull_up_en = 0,
.pull_down_en = 0,
.intr_type = GPIO_INTR_DISABLE
};
gpio_config(&io);
while (1) {
// Richtung 1
gpio_set_level(PIN_DIR, 1);
step_pulses(200, 5000); // 100 Hz: 5 ms High + 5 ms Low pro Schritt
vTaskDelay(pdMS_TO_TICKS(500));
// Richtung 2
gpio_set_level(PIN_DIR, 0);
step_pulses(200, 5000); // wieder 100 Hz
vTaskDelay(pdMS_TO_TICKS(800));
}
}