51 pinMode(csPin, OUTPUT);
52 digitalWrite(csPin, HIGH);
64 lastStatus = transfer((0x20 | (address & 0b11111)) << 1);
65 uint8_t data = transfer(0);
73 return readReg((uint8_t)address);
77 uint8_t
writeReg(uint8_t address, uint8_t value)
85 lastStatus = transfer((address & 0b11111) << 1);
86 uint8_t oldData = transfer(value);
101 SPISettings settings = SPISettings(500000, MSBFIRST, SPI_MODE1);
103 uint8_t transfer(uint8_t value)
105 return SPI.transfer(value);
110 digitalWrite(csPin, LOW);
111 SPI.beginTransaction(settings);
116 SPI.endTransaction();
117 digitalWrite(csPin, HIGH);
223 IncSlowDecMixed30 = 0b001,
224 IncSlowDecMixed60 = 0b010,
225 IncSlowDecFast = 0b011,
228 SmartTuneDynamicDecay = 0b110,
229 SmartTuneRippleControl = 0b111,
249 MicroStep16 = 0b0110,
250 MicroStep32 = 0b0111,
251 MicroStep64 = 0b1000,
252 MicroStep128 = 0b1001,
253 MicroStep256 = 0b1010,
365 if (percent > 100) { percent = 100; }
366 if (percent < 6) { percent = 6; }
368 uint8_t td = ((uint16_t)percent * 4 + 3) / 25;
370 ctrl1 = (ctrl1 & 0b00001111) | (td << 4);
395 if (fullCurrent > 4000) { fullCurrent = 4000; }
396 if (current > fullCurrent) { current = fullCurrent; }
398 uint8_t td = (current * 16 / fullCurrent);
399 if (td == 0) { td = 1; }
401 ctrl1 = (ctrl1 & 0b00001111) | (td << 4);
427 ctrl2 = (ctrl2 & 0b11111000) | (((uint8_t)mode & 0b111) << 8);
457 return (ctrl3 >> 7) & 1;
519 if (mode > DRV8434SStepMode::MicroStep256)
522 mode = DRV8434SStepMode::MicroStep16;
525 ctrl3 = (ctrl3 & 0b11110000) | (uint8_t)mode;
544 case 1: sm = DRV8434SStepMode::MicroStep1;
break;
545 case 2: sm = DRV8434SStepMode::MicroStep2;
break;
546 case 4: sm = DRV8434SStepMode::MicroStep4;
break;
547 case 8: sm = DRV8434SStepMode::MicroStep8;
break;
548 case 16: sm = DRV8434SStepMode::MicroStep16;
break;
549 case 32: sm = DRV8434SStepMode::MicroStep32;
break;
550 case 64: sm = DRV8434SStepMode::MicroStep64;
break;
551 case 128: sm = DRV8434SStepMode::MicroStep128;
break;
552 case 256: sm = DRV8434SStepMode::MicroStep256;
break;
555 default: sm = DRV8434SStepMode::MicroStep16;
621 if (!cachedReg) {
return 0; }
637 if (!cachedReg) {
return; }
644 uint8_t ctrl1, ctrl2, ctrl3, ctrl4, ctrl5, ctrl6, ctrl7;
652 case DRV8434SRegAddr::CTRL1:
return &ctrl1;
653 case DRV8434SRegAddr::CTRL2:
return &ctrl2;
654 case DRV8434SRegAddr::CTRL3:
return &ctrl3;
655 case DRV8434SRegAddr::CTRL4:
return &ctrl4;
656 case DRV8434SRegAddr::CTRL5:
return &ctrl5;
657 case DRV8434SRegAddr::CTRL6:
return &ctrl6;
658 case DRV8434SRegAddr::CTRL7:
return &ctrl7;
659 default:
return nullptr;
667 if (!cachedReg) {
return; }
@ STL_LRN_OK
Stall detection learning successful.
@ OTW
Overtemperature warning.
@ OTS
Overtemperature shutdown.
@ STALL
Motor stall condition.
DRV8434SDecayMode
Possible arguments to setDecayMode().
@ OCP_HS2_A
Overcurrent fault on high-side FET of half bridge 2 in AOUT.
@ OCP_LS2_A
Overcurrent fault on low-side FET of half bridge 2 in AOUT.
@ OCP_LS2_B
Overcurrent fault on low-side FET of half bridge 2 in BOUT.
@ OCP_HS2_B
Overcurrent fault on high-side FET of half bridge 2 in BOUT.
@ OCP_LS1_B
Overcurrent fault on low-side FET of half bridge 1 in BOUT.
@ OCP_HS1_A
Overcurrent fault on high-side FET of half bridge 1 in AOUT.
@ OCP_LS1_A
Overcurrent fault on low-side FET of half bridge 1 in AOUT.
@ OCP_HS1_B
Overcurrent fault on high-side FET of half bridge 1 in BOUT.
@ SPI_ERROR
SPI protocol error (latched)
@ UVLO
Supply undervoltage lockout fault.
@ CPUV
Charge pump undervoltage fault.
@ TF
Overtemperature warning or shutdown.
DRV8434SRegAddr
Addresses of control and status registers.
DRV8434SStepMode
Possible arguments to setStepMode().
@ MicroStep2_NC
Non-circular 1/2 step.
@ MicroStep1_100
Full step with 100% current.
@ MicroStep2
Circular 1/2 step.
@ MicroStep1
Full step with 71% current.
uint8_t getCachedReg(DRV8434SRegAddr address)
void enableSPIDirection()
void setReg(DRV8434SRegAddr address, uint8_t value)
void setDecayMode(DRV8434SDecayMode mode)
void writeCachedReg(DRV8434SRegAddr address)
Writes the cached value of the given register to the device.
void setChipSelectPin(uint8_t pin)
void setCurrentMilliamps(uint16_t current, uint16_t fullCurrent=2000)
void setDirection(bool value)
void disableDriver()
Disables the driver (EN_OUT = 0).
uint8_t * cachedRegPtr(DRV8434SRegAddr address)
void setStepMode(DRV8434SStepMode mode)
void setStepMode(uint16_t mode)
void setCurrentPercent(uint8_t percent)
void enableDriver()
Enables the driver (EN_OUT = 1).
void disableSPIDirection()
DRV8434S()
The default constructor.
void setChipSelectPin(uint8_t pin)
uint8_t readReg(uint8_t address)
Reads the register at the given address and returns its raw value.
uint8_t writeReg(uint8_t address, uint8_t value)
Writes the specified value to a register.
void writeReg(DRV8434SRegAddr address, uint8_t value)
Writes the specified value to a register.
uint16_t readReg(DRV8434SRegAddr address)
Reads the register at the given address and returns its raw value.