Only check for errors if the driver is initialized
parent
739f4cd2a3
commit
abf25c2b3e
|
|
@ -9,6 +9,8 @@ namespace tmc2130 {
|
||||||
static constexpr uint8_t TOFF_DEFAULT = 3U, TOFF_MASK = 0xFU;
|
static constexpr uint8_t TOFF_DEFAULT = 3U, TOFF_MASK = 0xFU;
|
||||||
|
|
||||||
bool TMC2130::Init(const MotorParams ¶ms, const MotorCurrents ¤ts, MotorMode mode) {
|
bool TMC2130::Init(const MotorParams ¶ms, const MotorCurrents ¤ts, MotorMode mode) {
|
||||||
|
initialized = false;
|
||||||
|
|
||||||
// sg_filter_threshold = (1 << (8 - params.mRes));
|
// sg_filter_threshold = (1 << (8 - params.mRes));
|
||||||
sg_filter_threshold = 2;
|
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.
|
/// Stallguard is also disabled if the velocity falls below this.
|
||||||
/// Should be set as high as possible when homing.
|
/// Should be set as high as possible when homing.
|
||||||
SetMode(params, mode);
|
SetMode(params, mode);
|
||||||
|
|
||||||
|
initialized = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -102,6 +106,9 @@ void TMC2130::SetEnabled(const MotorParams ¶ms, bool enabled) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TMC2130::CheckForErrors(const MotorParams ¶ms) {
|
bool TMC2130::CheckForErrors(const MotorParams ¶ms) {
|
||||||
|
if (!initialized)
|
||||||
|
return false;
|
||||||
|
|
||||||
uint32_t GSTAT = ReadRegister(params, Registers::GSTAT);
|
uint32_t GSTAT = ReadRegister(params, Registers::GSTAT);
|
||||||
uint32_t DRV_STATUS = ReadRegister(params, Registers::DRV_STATUS);
|
uint32_t DRV_STATUS = ReadRegister(params, Registers::DRV_STATUS);
|
||||||
errorFlags.reset_flag |= !!(GSTAT & (1U << 0U));
|
errorFlags.reset_flag |= !!(GSTAT & (1U << 0U));
|
||||||
|
|
|
||||||
|
|
@ -172,6 +172,7 @@ private:
|
||||||
void _handle_spi_status(const MotorParams ¶ms, uint8_t status);
|
void _handle_spi_status(const MotorParams ¶ms, uint8_t status);
|
||||||
|
|
||||||
ErrorFlags errorFlags;
|
ErrorFlags errorFlags;
|
||||||
|
bool initialized = false;
|
||||||
bool enabled = false;
|
bool enabled = false;
|
||||||
uint8_t sg_filter_threshold;
|
uint8_t sg_filter_threshold;
|
||||||
uint8_t sg_filter_counter = 0;
|
uint8_t sg_filter_counter = 0;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue