-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I2C issue with M5Stack STEPPER MOTOR module #192
Comments
Update: |
Ouch. Good luck tracking that down. Looking forward to hearing what you learn. |
Update: Investigating it. |
Update: e.g. const REGISTERS = {
I2C_MST_CNTRL: 0x24,
I2C_SLV0_ADDR: 0x25,
I2C_SLV0_REG: 0x26,
I2C_SLV0_DO: 0x63,
I2C_SLV0_CTRL: 0x27,
INT_BYPASS: 0x37,
ACCEL_XOUT: 0x3B, //big endian
ACCEL_YOUT: 0x3D,
ACCEL_ZOUT: 0x3F,
TEMP_OUT: 0x41,
GYRO_XOUT: 0x43,
GYRO_YOUT: 0x45,
GYRO_ZOUT: 0x47,
EXT_SENS_DATA_00: 0x49,
USER_CNTRL: 0x6A,
PWR_MGMT_1: 0x6B,
PWR_MGMT_2: 0x6C,
WHO_AM_I: 0x75
};
const I2C_MST_EN = 0x20;
const I2C_MST_CLK = 0x0D;
const I2C_SLV0_EN = 0x80;
...
enable() {
this.writeByte(REGISTERS.PWR_MGMT_1, 0);
this.writeByte(REGISTERS.INT_BYPASS, 0);
// Indirect peripheral access
this.writeByte(REGISTERS.USER_CNTRL, I2C_MST_EN);
this.writeByte(REGISTERS.I2C_MST_CNTRL, I2C_MST_CLK);
Timer.delay(150);
}
...
get MasterBus() {
let that = this;
return class {
constructor(dictionary) {
this.config = dictionary;
}
readBlock(register, count, buffer) {
that.writeByte(REGISTERS.I2C_SLV0_ADDR, this.config.address | 0x80);
that.writeByte(REGISTERS.I2C_SLV0_REG, register);
that.writeByte(REGISTERS.I2C_SLV0_CTRL, I2C_SLV0_EN | count);
Timer.delay(1);
return that.readBlock(REGISTERS.EXT_SENS_DATA_00, count, buffer);
}
writeBlock(register, ...value) {
that.writeByte(REGISTERS.I2C_SLV0_ADDR, this.config.address);
that.writeByte(REGISTERS.I2C_SLV0_REG, register);
that.writeBlock(REGISTERS.I2C_SLV0_DO, ...value);
return that.writeByte(REGISTERS.I2C_SLV0_CTRL, I2C_SLV0_EN | value.length);
}
writeByte(register, value) {
return this.writeBlock(register, value & 0xFF);
}
writeWord(register, value, endian) {
if (endian)
return this.write(register, (value >> 8) & 255, value & 255);
else
return this.write(register, value & 255, (value >> 8) & 255);
}
readByte(register) {
return this.readBlock(register, 1)[0];
}
readWord(register, endian) {
let value = this.readBlock(register, 2);
return endian ? (value[1] | (value[0] << 8)) : (value[0] | (value[1] << 8));
}
};
} |
Glad to hear you were able to resolve it from your script. Would a pull request make sense so others can use this too? |
I've tried to communicate with the STEPPER MOTOR module using the following code, it kept getting
0xFF
response from the device. I've tried changing the bus speed slower/faster, but no avail. For sending, it doesn't work as well, with exceptions thrown (except fori2c.write()
without parameters).I've compared the MicroPython driver and this, they don't look that different to me.
Then I looked at their GRBL firmware and schematics - which the only curiosity I could spot is the GPIO16, GPIO17 connection, possible for the alternative UART firmware.
It's supposed to grab the GRBL header when the (Arduino) module boots up. The same hardware has been tested on the MicroPython firmware with the following (similar) code, which they worked fine:
The text was updated successfully, but these errors were encountered: