I2C writing on config register TI driver DRV10987

Hi guys,

I’m working on 3 phases BLDC driver (DRV 10987 datasheet drv10987.pdf), and I have some difficult with the writing on Config register.

I’m not be able to write on config register to set up the driver.

Here is the part of code that should write on register:

/*=========================================
  DRIVER REGISTER
 ==========================================*/
#define driverAddress 0x52

#define driverFaultRegister 0x00
#define driverSpeedFeedback 0x01

#define driverConfigRegister_1 0x90
#define driverConfigRegister_2 0x91
#define driverConfigRegister_3 0x92
#define driverConfigRegister_4 0x93
#define driverConfigRegister_5 0x94
#define driverConfigRegister_6 0x95
#define driverConfigRegister_7 0x96

int configFeedback_1 = 99;
int configFeedback_2 = 99;
int configFeedback_3 = 99;
int configFeedback_4 = 99;
int configFeedback_5 = 99;
int configFeedback_6 = 99;
int configFeedback_7 = 99;

//============================================


void driverConfigurationRegister() {

  Serial.println("----------start writing config register----------");
  Serial.println("");
  
  //Config Register #1
  Wire.beginTransmission(driverAddress);
  Wire.write(driverConfigRegister_1);
  Wire.write(0xC0);
  Wire.write(0x5D);
  configFeedback_1 = Wire.endTransmission();
  Serial.print("Config REG_1: ");
  Serial.println(configFeedback_1, DEC);

  delay(100);

  //Config Register #2
  Wire.beginTransmission(driverAddress);
  Wire.write(driverConfigRegister_2);
  Wire.write(0x4A);
  Wire.write(0x49);
  configFeedback_2 = Wire.endTransmission();
  Serial.print("Config REG_2: ");
  Serial.println(configFeedback_2, DEC);

  delay(100);

  //Config Register #3
  Wire.beginTransmission(driverAddress);
  Wire.write(driverConfigRegister_3);
  Wire.write(0x00);
  Wire.write(0x81);
  configFeedback_3 = Wire.endTransmission();
  Serial.print("Config REG_3: ");
  Serial.println(configFeedback_3, DEC);

  delay(100);

  //Config Register #4
  Wire.beginTransmission(driverAddress);
  Wire.write(driverConfigRegister_4);
  Wire.write(0x37);
  Wire.write(0x92);
  configFeedback_4 = Wire.endTransmission();
  Serial.print("Config REG_4: ");
  Serial.println(configFeedback_4, DEC);

  delay(100);

  //Config Register #5
  Wire.beginTransmission(driverAddress);
  Wire.write(driverConfigRegister_5);
  Wire.write(0x3B);
  Wire.write(0xAF);
  configFeedback_5 = Wire.endTransmission();
  Serial.print("Config REG_5: ");
  Serial.println(configFeedback_5, DEC);
  

  delay(100);

  //Config Register #6
  Wire.beginTransmission(driverAddress);
  Wire.write(driverConfigRegister_6);
  Wire.write(0xD8);
  Wire.write(0x43);
  configFeedback_6 = Wire.endTransmission();
  Serial.print("Config REG_6: ");
  Serial.println(configFeedback_6, DEC);

  delay(100);

  //Config Register #7
  Wire.beginTransmission(driverAddress);
  Wire.write(driverConfigRegister_7);
  Wire.write(0x00);
  Wire.write(0x6A);
  configFeedback_7 = Wire.endTransmission();
  Serial.print("Config REG_7: ");
  Serial.println(configFeedback_7, DEC);
  
  Serial.println("----------End writing config register----------");
  
  delay(1000);
  
//-------------------------------------------------------------
  
  Serial.println("");
  Serial.println("");
  Serial.println("");
  Serial.println("----------Config registers value----------");
  Serial.println("");
  Serial.println("Config register:");
  
  //READ DRIVER SET UP REGISTER
  uint8_t Byte[14];
  
  Wire.beginTransmission(driverAddress); //0x52
  Wire.write(driverConfigRegister_1);
  Wire.endTransmission();

  Wire.requestFrom(driverAddress, 2);

  if(2 <= Wire.available()) {
    
    Byte[0] = Wire.read();
    Byte[1] = Wire.read();

    Serial.print("#1: ");
    Serial.print(Byte[0], HEX);
    Serial.println(Byte[1], HEX);
    
  }

  Wire.beginTransmission(driverAddress); //0x52
  Wire.write(driverConfigRegister_2);
  Wire.endTransmission();

  Wire.requestFrom(driverAddress, 2);

  if(2 <= Wire.available()) {
    
    Byte[2] = Wire.read();
    Byte[3] = Wire.read();

    Serial.print("#2: ");
    Serial.print(Byte[2], HEX);
    Serial.println(Byte[3], HEX);
    
  }

  Wire.beginTransmission(driverAddress); //0x52
  Wire.write(driverConfigRegister_3);
  Wire.endTransmission();

  Wire.requestFrom(driverAddress, 2);

  if(2 <= Wire.available()) {
    
    Byte[4] = Wire.read();
    Byte[5] = Wire.read();

    Serial.print("#3: ");
    Serial.print(Byte[4], HEX);
    Serial.println(Byte[5], HEX);
    
  }

Wire.beginTransmission(driverAddress); //0x52
  Wire.write(driverConfigRegister_4);
  Wire.endTransmission();

  Wire.requestFrom(driverAddress, 2);

  if(2 <= Wire.available()) {
    
    Byte[6] = Wire.read();
    Byte[7] = Wire.read();

    Serial.print("#4: ");
    Serial.print(Byte[6], HEX);
    Serial.println(Byte[7], HEX);
    
  }

  Wire.beginTransmission(driverAddress); //0x52
  Wire.write(driverConfigRegister_5);
  Wire.endTransmission();

  Wire.requestFrom(driverAddress, 2);

  if(2 <= Wire.available()) {
    
    Byte[8] = Wire.read();
    Byte[9] = Wire.read();

    Serial.print("#5: ");
    Serial.print(Byte[8], HEX);
    Serial.println(Byte[9], HEX);
    
  }

  Wire.beginTransmission(driverAddress); //0x52
  Wire.write(driverConfigRegister_6);
  Wire.endTransmission();

  Wire.requestFrom(driverAddress, 2);

  if(2 <= Wire.available()) {
    
    Byte[10] = Wire.read();
    Byte[11] = Wire.read();

    Serial.print("#6: ");
    Serial.print(Byte[10], HEX);
    Serial.println(Byte[11], HEX);
    
  }

  Wire.beginTransmission(driverAddress); //0x52
  Wire.write(driverConfigRegister_7);
  Wire.endTransmission();

  Wire.requestFrom(driverAddress, 2);

  if(2 <= Wire.available()) {
    
    Byte[12] = Wire.read();
    Byte[13] = Wire.read();

    Serial.print("#7: ");
    Serial.print(Byte[12], HEX);
    Serial.println(Byte[13], HEX);
    
  }
  Serial.println("----------End check config register----------");
  Serial.println("");
  Serial.println("");
  
}

I added a feedback from .endTransmission() end it always return 0, so the transmission should be successful.

Moreover after the writing I checked the register with read() function, but the response is always 0x0000.

In the picture I captured the serial monitor response after setup.

So I do not understand what is wrong :confused:

The only way to program the driver config register is with TI software, if I start up the driver with TI software the BLDC motor works and I’m able to read the fault register and the speed register.

Someone could help me ?

Thank you.

Try to change

  Wire.beginTransmission(driverAddress); //0x52
  Wire.write(driverConfigRegister_1);
  Wire.endTransmission();

  Wire.requestFrom(driverAddress, 2);

to

  Wire.beginTransmission(driverAddress); //0x52
  Wire.write(driverConfigRegister_1);
  Wire.endTransmission(false);

  Wire.requestFrom(driverAddress, 2);

This chip needs a repeated start condition to read values. Providing the false argument to Wire.endTransmission() omits the stop condition after the write.

So, I solved the issue I had forgotten to store in driver EEPROM memory the shadow config register. :sweat_smile:

Your answer

This chip needs a repeated start condition to read values. Providing the false argument to Wire.endTransmission() omits the stop condition after the write.

gave me a doubt.

You said that this driver needs a repeated start condition, it's right and I know that Wire.endTransmission() has true argument by default so you suggest to providing false argument to prevent te stop condition.

All right, but I tried with and without false condition and the result are always the same, serial monitor give me back a right value from registers for example speed, frequency, driver fault...

So I'm only lucky ? :grinning:

Anyhow to be more comfortable, do you suggest me to providing a false condition for all .endTransmission() after writing ?

Thank you.

So I'm only lucky ?

No, that probably means the datasheet shows a repeated start condition but it works also with standard start/stop condition requests.

Anyhow to be more comfortable, do you suggest me to providing a false condition for all .endTransmission() after writing ?

I probably would do so to exactly follow the datasheet but I guess it's not necessary.

Part of the data sheets of DRV10987 Sensor:
wr.png

The data sheet clearly indicates the following:
1. A register (for example: CONFIG1) has 8-bit address; but, it is 16-bit wide; so, the user is required to queue 16-it data as 2 discrete bytes in the I2C Bus.

2. The I2C Bus timing diagram (I2C Write) shows that the user is required to assert STOP command with default argument true.

My understanding -- the data sheets do not recommend to assert STOP command with false argument before issuing the 'Wire.requstFrom()' command which brings START and STOP conditions on the I2C Bus in the background.

wr.png

So I wrote an article on working with this controller. There is also a sketch for flashing configuration register parameters.

Config calculator:
f0319644.xsph.ru