Tom Lindley
Tom Lindley

Reputation: 371

Driving a TMC5160 from ESP32

I am trying to use the TMC5160 library by Tom Magnier and having a couple of issues. I am using the SPI interface version of the BigTreeTech chip and have the following pins hooked up. Hardware setup :

    MOSI (ESP32 : 23)   <=> SDI
    MISO (ESP32 : 19)   <=> SDO
    SCK (ESP32 : 18)    <=> SCK
    ESP32:5             <=> CSN
    ESP32:25            <=> DRV_ENN (optional, tie to GND if not used)
    GND                 <=> GND
    3.3V (ESP32 : )     <=> VCC_IO (depending on the processor voltage)

I am basically just trying to implement the sample and it appears I can configure the driver with the defaults as it finds the chip and shows status. But, it will not respond to motor control. I am wondering if I am missing something in the connection to the ESP32.

My code for initialization and testing.

void izTMC5160::Initialize()
{
    _log->Log("izTMC5160::Initialize starting...");
    pinMode(_enablePin, OUTPUT); 
    digitalWrite(_enablePin, LOW); // Active low

    SPI.begin();

    // This sets the motor & driver parameters /!\ run the configWizard for your driver and motor for fine tuning !
    powerStageParams.drvStrength = 2;
    powerStageParams.bbmTime = 24;
    powerStageParams.bbmClks = 0;
    motorParams.globalScaler = 219;
    motorParams.irun = 31;
    motorParams.ihold = 15;
//    motorParams.freewheeling = 0;
    motorParams.pwmOfsInitial = 30;
    motorParams.pwmGradInitial = 0;
    motor.begin(powerStageParams, motorParams, TMC5160::NORMAL_MOTOR_DIRECTION);

    // ramp definition
    motor.setRampMode(TMC5160::POSITIONING_MODE);
    motor.setMaxSpeed(_maxSpeed);
    motor.setAcceleration(_acceleration);
    delay(_startupDelay); // Standstill for automatic tuning
    _log->Log("izTMC5160::Initialize completed...");
}

void izTMC5160::Test()
{
    _testDir = !_testDir;
    motor.setTargetPosition(_testDir ? _testSteps : -_testSteps);  // 1 full rotation = 200s/rev
    float xactual = motor.getCurrentPosition();
    float vactual = motor.getCurrentSpeed();
    char buffer[256];
    sprintf(buffer, "izTMC5160::Test - Current position: %f Current Speed: %f",xactual,vactual);
    _log->Log(buffer);
}

void izTMC5160::Enable(bool enable)
{
    if(enable)
    {
        digitalWrite(_enablePin,LOW);
    }
    else
    {
        digitalWrite(_enablePin,HIGH);
    }
}

Upvotes: 1

Views: 2111

Answers (1)

jenny darbs
jenny darbs

Reputation: 21

the example works, my guess is you have not enabled motion control mode. the bigtree tech tmc5160 doesnt offer an easy way to adjust spi and sd mode selectors,there version one did hopefully the next batch will also. see here for fix :https://github.com/bigtreetech/BIGTREETECH-TMC5160-V1.0/issues/8

Upvotes: 1

Related Questions