SPI communication with A89053 Motor Driver Chip

Hi all,

I'm new to SPI and a bit in at the deep end here. I'm trying to talk to this chip (A89503) over SPI. It has a bunch of registers that are WRITE(such as the gates), but at the moment I'm trying to READ from any of the 3 diagnostics channels. (refer to P.28, Table 6 in datasheet linked).
https://www.allegromicro.com/-/media/files/datasheets/a89503-datasheet.ashx
At the moment I'm just trying to read from Diag0 listed there using the code below as a test.
It's a 16 bit register so am sending 2 bytes each time.
weird thing I can't figure out is that presumably the chip will wait to receive all 16bits before sending any data, but then I can only see how I could receive one byte back, just because of how the arduino library seems to work there. So what am I doing wrong / misunderstanding here please, or can I not use Arduino for this functionality?

Thanks,
John

// SPI config test for SAMD21

#include <SPI.h>
#include "wiring_private.h" // pinPeripheral() function
  
SPIClass mySPI (&sercom1, 12, 13, 11, SPI_PAD_0_SCK_1, SERCOM_RX_PAD_3);
//D3 for chip select pin
const int chipSelectPin = 3;
unsigned int result = 0;   // result to return

void setup() {
  Serial.begin(115200);
  // initalize the chip select pins:
  pinMode(chipSelectPin, OUTPUT);
  // do this first, for Reasons
  mySPI.begin();

  // Assign pins 11, 12, 13 to SERCOM functionality
  pinPeripheral(11, PIO_SERCOM);
  pinPeripheral(12, PIO_SERCOM);
  pinPeripheral(13, PIO_SERCOM);
}


void loop() {
  mySPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
  digitalWrite(chipSelectPin, LOW);
  mySPI.transfer(0b11000000);
  result = mySPI.transfer(0b00000001);
  digitalWrite(chipSelectPin, HIGH);
  mySPI.endTransaction();
  Serial.println("chip select sent");
  Serial.print("data sent: ");
  Serial.println(0b11000000, BIN);
  Serial.println(0b00000001, BIN);
  delay(500);
  Serial.print("data received: ");
  Serial.println(result, BIN);
  delay (1000);

}

If you are "new" to SPI, I recommend to start with a device that is not quite so mysterious, and where there are some Arduino examples to study.

SPI is not as well standardized as other serial protocols. There don't appear to be any Arduino examples or libraries for the A89503, so if you insist on starting with it, you are on your own and will need to study the data sheet VERY carefully.

For example, how do you know that SPI_MODE0 is the correct choice?

Thanks. I suppose I was hoping that someone on this forum would have some experience of the chip.
I have bought an SPI pressure sensor that seems to be more used, so hopefully that will help with my basic understanding.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.