7#define TMC_WRITE_BIT 0x80
21 TMC7300IC(uint8_t _pin, uint8_t _chipAddress, uint32_t _baudrate = 100000)
25 _baudrate = constrain(_baudrate, 10000, 100000);
33 void begin(
boolean _extcap =
true, uint8_t _irun = 31)
37 digitalWrite(
pin, HIGH);
55 didSomething |= 0b100;
60 didSomething |= 0b01000;
79 0, 0, 0, 0, 0, (uint32_t)0b1111100000001, 0, (uint32_t)0x13008001, 0, (uint32_t)0xC40D1024};
107 uint32_t registerValueReceived = 0;
125 uint8_t addressWrite = address | TMC_WRITE_BIT;
126 uint8_t writeRequest[8] = { SYNC_BYTE,
chipAddress, addressWrite, 0, 0, 0, 0, 0 };
129 writeRequest[3] = (value >> 24) & 0xFF;
130 writeRequest[4] = (value >> 16) & 0xFF;
131 writeRequest[5] = (value >> 8) & 0xFF;
132 writeRequest[6] = (value) & 0xFF;
135 writeRequest[7] =
calcCRC(writeRequest, 7);
137 pinMode(
pin, OUTPUT);
138 digitalWrite(
pin, HIGH);
140 unsigned long m = micros();
141 for (
int j = 0; j < 8; j++) {
142 digitalWrite(
pin, LOW);
145 for (
int i = 0; i < 8; i++) {
146 digitalWrite(
pin, (writeRequest[j] >> i) & 0x01);
150 digitalWrite(
pin, HIGH);
165 uint8_t addressRead = address & 0b01111111;
166 uint8_t readRequest[4] = { SYNC_BYTE,
chipAddress, addressRead, 0 };
167 readRequest[3] =
calcCRC(readRequest, 3);
169 uint8_t response[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
171 pinMode(
pin, OUTPUT);
172 digitalWrite(
pin, HIGH);
176 unsigned long m = micros();
178 for (j = 0; j < 4; j++) {
179 digitalWrite(
pin, LOW);
182 for (uint8_t i = 0; i < 8; i++) {
183 digitalWrite(
pin, (readRequest[j] >> i) & 0x01);
187 digitalWrite(
pin, HIGH);
191 pinMode(
pin, INPUT_PULLUP);
193 delayMicroseconds(20);
194 for (j = 0; j < 8; j++) {
196 while (digitalRead(
pin) == HIGH && micros() - m < 3000) { }
198 if (micros() - m >= 3000) {
204 for (uint8_t i = 0; i < 8; i++) {
207 response[j] |= (digitalRead(
pin) << i);
212 while (micros() - m <
uartDelay && digitalRead(
pin) == LOW) { }
213 delayMicroseconds(1);
218 pinMode(
pin, OUTPUT);
219 digitalWrite(
pin, HIGH);
221 if (response[1] != 0xFF) {
224 if (response[2] != addressRead) {
227 if (response[7] !=
calcCRC(response, 7)) {
231 value = (response[3] << 24) | (response[4] << 16) | (response[5] << 8) | response[6];
TMCField TMC7300_IRUN(_TMC7300_CURRENT_LIMIT, _TMC7300_IRUN_MASK, _TMC7300_IRUN_SHIFT, _TMC7300_CURRENT_LIMIT_VALUE_ADDR)
TMCField TMC7300_DRV_ERR(_TMC7300_GSTAT, _TMC7300_DRV_ERR_MASK, _TMC7300_DRV_ERR_SHIFT, _TMC7300_GSTAT_VALUE_ADDR)
TMCField TMC7300_PWM_DIRECT(_TMC7300_GCONF, _TMC7300_PWM_DIRECT_MASK, _TMC7300_PWM_DIRECT_SHIFT, _TMC7300_GCONF_VALUE_ADDR)
TMCField TMC7300_SLAVECONF(_TMC7300_SLAVECONF, _TMC7300_SLAVECONF_MASK, _TMC7300_SLAVECONF_SHIFT, _TMC7300_SLAVECONF_VALUE_ADDR)
TMCField TMC7300_ENABLEDRV(_TMC7300_CHOPCONF, _TMC7300_ENABLEDRV_MASK, _TMC7300_ENABLEDRV_SHIFT, _TMC7300_CHOPCONF_VALUE_ADDR)
TMCField TMC7300_EXTCAP(_TMC7300_GCONF, _TMC7300_EXTCAP_MASK, _TMC7300_EXTCAP_SHIFT, _TMC7300_GCONF_VALUE_ADDR)
uint8_t calcCRC(uint8_t data[], uint8_t dataLength)
Definition TMCSerial.h:9
Top level class for the TMC7300 library. This class controls a TMC7300 chip. https://www....
Definition TMC7300.h:13
boolean extcap
Definition TMC7300.h:74
void begin(boolean _extcap=true, uint8_t _irun=31)
begin communication with the TMC7300
Definition TMC7300.h:33
boolean readRegister(uint8_t address, uint32_t &value)
read data from a register in the TMC7300
Definition TMC7300.h:163
uint32_t uartDelay
Definition TMC7300.h:73
int checkDriver()
check if the TMC7300's settings match the settings they should have and reset them if they don't
Definition TMC7300.h:49
void writeRegister(uint8_t address, uint32_t value)
write data to a register in the TMC7300
Definition TMC7300.h:122
uint8_t getChipAddress()
get the chipAddress of the TMC7300
Definition TMC7300.h:240
uint8_t chipAddress
Definition TMC7300.h:72
uint32_t registers[10]
Definition TMC7300.h:77
TMC7300IC(uint8_t _pin, uint8_t _chipAddress, uint32_t _baudrate=100000)
constructor for class that controls a TMC7300 chip.
Definition TMC7300.h:21
void writeField(TMCField field, uint32_t fieldValue, boolean write=true)
write data to a field of a register in the TMC7300 (see TMC7300_Map.h and the TMC7300 datasheet for m...
Definition TMC7300.h:90
uint8_t pin
Definition TMC7300.h:71
uint32_t readField(TMCField field, boolean read=true)
read data from a field of a register in the TMC7300 (see TMC7300_Map.h and the TMC7300 datasheet for ...
Definition TMC7300.h:105
uint32_t address()
Definition TMC_Field.h:31
uint32_t getField(uint32_t registerValue)
Definition TMC_Field.h:25
uint32_t setField(uint32_t fieldValue, uint32_t registerValue)
Definition TMC_Field.h:19
uint32_t valueAddress()
Definition TMC_Field.h:35