Other Parts Discussed in Thread: DRV8323
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Dilip,
Thanks for posting on the MD forum!
Regards,
-Adam
Thank Adam,
I have written a code for SPI communication for changing 6xPWM mode to 1xPWM mode for Arduino mega board.
Can you please check the code? I am facing problem in reading the register.
The code is
#include <SPI.h>
const int chipselect = 53;
const int enable = 8;
void setup() {
Serial.begin(9600);
pinMode(chipselect, OUTPUT);
pinMode(enable, OUTPUT);
digitalWrite(enable, LOW);
digitalWrite(chipselect, LOW);
SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE1);
digitalWrite(enable, HIGH);
delay(20);
}
void loop()
{
writereg(0x04,0xA7); // adderess = 0000 0100, data = 1(fault) 000 0111 // last 111 for converting 6xPWM into 1xPWM mode
readreg(0x84); /// address= 1(read) 000 0100
delay(1000);
}
void writereg(byte address, byte data)
{
byte HSend = 0x00,LSend = 0x00,HRead = 0x00,LRead = 0x00;
HSend = address;
LSend = data;
Serial.print("Sending write command: ");
Serial.print(HSend,HEX);Serial.print(" "); Serial.println(LSend,HEX);
digitalWrite(chipselect, LOW);
SPI.transfer(HSend);
SPI.transfer(LSend);
digitalWrite(chipselect, HIGH);
Serial.print(HRead,HEX); Serial.print(" ");Serial.println(LRead,HEX);
}
unsigned int readreg(byte address ) {
byte HSend = 0x00,LSend = 0x00,HRead = 0x00,LRead = 0x00;
HSend = address;
Serial.print("Sending read command: ");
Serial.print(HSend,HEX);Serial.print(" ");Serial.println(LSend,HEX);
digitalWrite(chipselect, LOW);
SPI.transfer(HSend);
SPI.transfer(LSend);
digitalWrite(chipselect, HIGH);
delay(20);
digitalWrite(chipselect, LOW);
HRead = SPI.transfer(0x00);
LRead = SPI.transfer(0x00);
digitalWrite(chipselect, HIGH);
Serial.print(HRead,HEX); Serial.print(" ");Serial.println(LRead,HEX);
}
After running this code, I have received read data as 0xA0 in place of 0xA7.
Thank you in advance.
I have few questions related to the above image ( a part of datasheet of drv8343).
Q1: The SDO output data word is 16 bits long and the first 5 bits are don't care bits, and SDO word shown in Table 12 has 7 don't care bits. Why?
Q2: For the statement "For a write command (W0 = 0), the response word on the SDO pin is the data currently in the register being
written to.". a. What is response word? Is it the data already written into in the register, or is it directly bypassing the SDI data to SDO?
b. If some bits sequence is available on SDO, does it mean that SPI communication is successful?
Q3: what are the steps required in reading the register? As there are differences in SDO word format of different drv such as drv8323, particularly B15 (W0) which is not available in other drv.
Dilip,
Q1) I am checking on this but I suspect this is a typo, usually the address in the SDO response is Don't Care so your 7 bits would be correct.
Q2) I am checking on this.
b) No, movement on the SDO line does not imply SPI is working completely, it may be working partially. For example there could be data integrity issues because a GND is missing or something.
Q3) The steps are standard SPI and are mentioned in the datasheet here at section "8.5.1.1.1 SPI Format"
Regards,
-Adam
Dilip,
I have confirmed that yes Q1 is a typo, is should be 7 don't care bits.
Regards,
-Adam
Dilip,
I have seen no update on this thread, did your issue get resolved?
I will mark this thread as closed for now but please post again if you need further assistance.
Regards,
-Adam