diff --git a/src/hal/tmc2130.cpp b/src/hal/tmc2130.cpp index eb00727..da281af 100644 --- a/src/hal/tmc2130.cpp +++ b/src/hal/tmc2130.cpp @@ -9,6 +9,8 @@ namespace tmc2130 { static constexpr uint8_t TOFF_DEFAULT = 3U, TOFF_MASK = 0xFU; bool TMC2130::Init(const MotorParams ¶ms, const MotorCurrents ¤ts, MotorMode mode) { + initialized = false; + // sg_filter_threshold = (1 << (8 - params.mRes)); sg_filter_threshold = 2; @@ -65,6 +67,8 @@ bool TMC2130::Init(const MotorParams ¶ms, const MotorCurrents ¤ts, Mot /// Stallguard is also disabled if the velocity falls below this. /// Should be set as high as possible when homing. SetMode(params, mode); + + initialized = true; return true; } @@ -102,6 +106,9 @@ void TMC2130::SetEnabled(const MotorParams ¶ms, bool enabled) { } bool TMC2130::CheckForErrors(const MotorParams ¶ms) { + if (!initialized) + return false; + uint32_t GSTAT = ReadRegister(params, Registers::GSTAT); uint32_t DRV_STATUS = ReadRegister(params, Registers::DRV_STATUS); errorFlags.reset_flag |= !!(GSTAT & (1U << 0U)); diff --git a/src/hal/tmc2130.h b/src/hal/tmc2130.h index d54ebbe..b56aaf5 100644 --- a/src/hal/tmc2130.h +++ b/src/hal/tmc2130.h @@ -172,6 +172,7 @@ private: void _handle_spi_status(const MotorParams ¶ms, uint8_t status); ErrorFlags errorFlags; + bool initialized = false; bool enabled = false; uint8_t sg_filter_threshold; uint8_t sg_filter_counter = 0;