Hi Koepel, thank you!
Yes, the datasheet is a monster, lots and lots of information. And sorry, here is the sketch. I had issues copy+pasting the serial monitor (new in Arduino Ide too..), but I will try that too.
#include <Wire.h>
#define BRAKE 5
#define DIR 17
#define SPEED 16
const int deviceAddress = 0x01;
#define CRC_POLYNOMIAL 0x07
void setup() {
Wire.begin();
Serial.begin(115200);
Serial.println("Starting");
pinMode(BRAKE, OUTPUT);
pinMode(DIR, OUTPUT);
pinMode(SPEED, OUTPUT);
digitalWrite(BRAKE, HIGH);
digitalWrite(DIR, HIGH);
digitalWrite(SPEED, LOW);
uint8_t data[] = {0x02, 0x50, 0x00, 0xA4, 0x01, 0x00, 0x00, 0x00};
uint8_t crc = calculateCRC(data, sizeof(data));
Wire.beginTransmission(deviceAddress);
Wire.write((uint8_t)(0x02)); // Start Byte
delay(100);
Wire.write((uint8_t)(0x50)); // control Word 0
delay(100);
Wire.write((uint8_t)(0x00)); // Control word 1
delay(100);
Wire.write((uint8_t)(0xA4)); // Control word 2
delay(100);
Wire.write((uint8_t)(0x01)); // Data Bytes 0
delay(100);
Wire.write((uint8_t)(0x00)); // Data Bytes 1
delay(100);
Wire.write((uint8_t)(0x00)); // Data Bytes 2
delay(100);
Wire.write((uint8_t)(0x00)); // Data Bytes 3
delay(100);
Wire.write(crc); // Data Bytes 3
delay(100);
Wire.endTransmission();
delay(1000);
}
void loop() {
Serial.println("Motor should start");
analogWrite(SPEED, 128);
digitalWrite(BRAKE, LOW);
delay(5000);
Serial.println("Speed increase");
analogWrite(SPEED, 200);
delay(3000);
digitalWrite(BRAKE, HIGH);
Serial.println("Motor Stops");
delay(2000);
digitalWrite(DIR, LOW);
analogWrite(SPEED, 128);
digitalWrite(BRAKE, LOW);
Serial.println("Motor should start in reverse direction");
delay(5000);
analogWrite(SPEED, 200);
Serial.println("Speed increase");
delay(3000);
digitalWrite(BRAKE, HIGH);
Serial.println("Motor Stops");
delay(2000);
digitalWrite(DIR, HIGH);
}
uint8_t calculateCRC(uint8_t* data, uint8_t length) {
uint8_t crc = 0xFF; // Initial CRC value
for (uint8_t i = 0; i < length; i++) {
crc ^= data[i]; // XOR the CRC with the current data byte
for (uint8_t j = 0; j < 8; j++) {
if (crc & 0x80) { // Check if the most significant bit is set (bit 7)
crc = (crc << 1) ^ CRC_POLYNOMIAL; // Shift left and XOR with the polynomial
} else {
crc <<= 1; // Just shift left
}
}
}
return crc;
}
I am not the programmer, but I will try to answer as best as I can.
-We have scanned I2C devices, and found this. 0x01 was the address shown.
-For the CRC I couldn't find the default setting
-For the NACK same, couldn't find the maximum time after it should be ready. What do you suggest, adding delay somewhere?
-Delay after write, in datasheet we found "For reliable communication, a 100-µs delay should be used between every byte transferred over the I2C bus." so maybe we misunderstood this.
-So Wire.endTransmission() will send data to the driver? Or how is it should be used?
I forwarded your reply to the programmer and asked her to join here for discussion.