I am trying to run DRV8234 motor driver with arduino (datasheet).
I have the following code:
#include <Wire.h>
uint8_t write_address = 0x60, CONFIG4_REG=0x0D;
uint8_t config4_value = 0x00; // PMODE = 0 (EN/PH Mode), I2C_BC = 1
int in1 = 35, in2 = 34;
void setup() {
Serial.begin(115200);
Serial.println("\nI2C Scanner");
// pinMode(in1, OUTPUT);
// pinMode(in2, OUTPUT);
// digitalWrite(in1, HIGH);
// digitalWrite(in2, HIGH);
Wire.begin();
configureDRV8234();
}
void loop() {
}
int configFeedback_1 = 99;
void configureDRV8234() {
// Step 1: Enable I2C_BC in CONFIG4 Register
writeRegister(CONFIG4_REG, config4_value);
Serial.println("DRV8234 configured for EN/PH mode");
}
// Function to write to a register via I2C
void writeRegister(uint8_t reg, uint8_t value) {
Wire.beginTransmission(0x60); // A0 & A1 are both tied to ground
Wire.write(byte(0x09)); // CONFIG_REGISTER 0 address
Wire.write(byte(0b1000000)); // Enabling outputs
configFeedback_1 = Wire.endTransmission(false);
Serial.print("Config REG_1: ");
Serial.println(configFeedback_1, DEC);
Wire.requestFrom(0x60, 2);
if(2 <= Wire.available()) {
Wire.read();
Wire.read();
}
delay(100);
Wire.beginTransmission(0x60); // A0 & A1 are both tied to ground
Wire.write(byte(0x0D)); // CONFIG 4 register
Wire.write(byte(0b00000111)); // enabling bridge control by input pins. Both pins are high
configFeedback_1 = Wire.endTransmission(false);
Serial.print("Config REG_4: ");
Serial.println(configFeedback_1, DEC);
Wire.requestFrom(0x60, 2);
if(2 <= Wire.available()) {
Wire.read();
Wire.read();
}
delay(100);
}
This code doesn't seem to be working. Can someone help me with this.
You need to provide a closer description of " doesn't seem to be working".
Did You write the code?
Please post schematics.
Which "Arduino" are you using?
It is connected like this?
(Ref: https://www.ti.com/lit/ds/symlink/drv8234.pdf?ts=1732212929454)
Post your driver image/datasheet link.
Yes. It is connected according to the given typical application connection in datasheet. As well as I have drv8234 evm, the code is not working on that as well if I only connect SDA, SCL to esp32 and give A0, A1 ground and have common ground.
Post your driver image/datasheet link.
The motor doesn't seem to be moving even when I set the config registers correctly to have it moving.
Yes I wrote the code.
Datasheet: https://www.ti.com/lit/ds/symlink/drv8234.pdf?ts=1731522349395&ref_url=https%253A%252F%252Fwww.ti.com%252Fproduct%252FDRV8234%253FkeyMatch%253DDRV8234%2526tisearch%253Duniversal_search%2526usecase%253DGPN-ALT
The schematic is same as in the typical application section of the datasheet.
Can you please try this code? It should control only the motor output in PH/EN mode. Is this board recognized by I2C scanner?
#include <Wire.h>
#define ADDR 0x60
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Wire.begin();
writeI2CByte(0x09, 0b11100000);//BIT7 from CONFIG0 set to 1 in order to enable output EN_OUT
writeI2CByte(0x0D, 0b00110100);//CONFIG4, 0011 default 0 PH/EN 1 I2C X EN_IN1 X PH_IN2, where x controls those inputs from i2c
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(">>forward>>");
writeI2CByte(0x0D, 0b00110111);//forward
delay(5000);
Serial.println("<reverse<<");
writeI2CByte(0x0D, 0b00110110);//reverse
delay(5000);
Serial.println("><brake><");
writeI2CByte(0x0D, 0b00110100);//brake
delay(5000);
}
void writeI2CByte(byte data_addr, byte data){
Wire.beginTransmission(ADDR);
Wire.write(data_addr);
Wire.write(data);
Wire.endTransmission();
}
This should be correct now. I forgot the binary for all data (0b).