16 Bit SPI Communication with DRV8323 Reading Register Not Working

Hi,

I am using an Arduino UNO as a master controller to set/read registers in the DRV8323 gate driver board. I have been troubleshooting this problem for a week now and decided to ask.

My issue is that I cannot read or set the registers. In the datasheet for the DRV board, it needs a 16-bit word (MSB is shifted in and out first) to be sent - the first but in position 15 is 1 for READ and 0 for write. I am using the Arduino SPI library and believe I have set everything accordingly, here is the code:

#include <SPI.h>
#define SELECT 10

void setup() {
  Serial.begin(9600);
  
  pinMode(SELECT, OUTPUT);
  pinMode(SELECT, HIGH);
 
  // start the SPI library:
  SPI.begin();

  delay(500);
}

void loop() {
  readRegister();  
  delay(100);
}


void readRegister() {
  unsigned int response;
  
  SPI.beginTransaction(SPISettings(125000, MSBFIRST, SPI_MODE1));
  digitalWrite(SELECT, LOW);
  // Read address 0x03
  SPI.transfer16(0b1001100000000000);
  response = SPI.transfer16(0x00);
  //take the SS pin high to de-select the chip:
  digitalWrite(SELECT, HIGH);
  SPI.endTransaction();

  // Display the data
  Serial.println(response, BIN);
}

void writeRegister() {
  SPI.beginTransaction(SPISettings(125000, MSBFIRST, SPI_MODE1));
  digitalWrite(SELECT, LOW);
  // Set address 0x02 to 3x PWM mode
  SPI.transfer16(0b0001000000100000);
  digitalWrite(SELECT, HIGH);
  SPI.endTransaction();
}

When running the serial print displays 0s and then once in a while a seemingly ‘random’ binary number as follows:

0
0
0
0
0
0
0
1010000
0
0
0
0
0
0
0
0
0
...

My question is if I am properly sending the 16 bit words over SPI, and if not the proper way of doing it.

Thanks :slight_smile:

I wouldn't use the transfer16() method but the standard transfer() method to keep the control over the interface, but that's up to you.

In interpret the datasheet that way that you get the response in the same word as you send the command. That's why the first 5 bits are to be ignored, it must receive these 5 bits to know what to respond.

So

  SPI.transfer16(0b1001100000000000);
  response = SPI.transfer16(0x00);

should be changed to

  response = SPI.transfer16(0b1001100000000000);