Reading values from SPI encoder

I'm pretty new to SPI communication and trying to figure out how to communicate with a magnetic encoder. Now, I would just like to read out the warning and error bits from the encoder. I use pins 13-11 for SCK, MISO, MOSI as shown in the Image. Additionaly I have 3.3 V on the MSEL- Pin to select SPI communication Interface on the encoder as stated in the datasheet. Her is the datasheet: https://docs.broadcom.com/doc/AEAT-9922-Q24-10-to-18-Bit-Programmable-Angular-Magnetic-Encoder-IC-AN. What do I have to change in order to sucessfully read the Error Bits from the Address 0x21 as stated in the Datasheet Page 5?

#include <SPI.h>

const int slaveSelectPin = 10; // Define Slave Select Pin

void setup() {
  Serial.begin(9600);
  pinMode(slaveSelectPin, OUTPUT);
  SPI.begin();
  SPI.setBitOrder(MSBFIRST); // Define Data Structure
  SPI.setDataMode(SPI_MODE1); // Define SPI Mode for CPOL = 0 and CPHA = 1
  digitalWrite(slaveSelectPin, LOW); //Start Communication
  SPI.transfer(0x21); //Sending Addredss for Read
  unsigned int error = SPI.transfer(0x00);
  digitalWrite(slaveSelectPin, HIGH); //End Communication
  Serial.println(error);
}

void loop() {
  
}

Thanks a lot for everyone's help!

You may need to change your code like this:

#include <SPI.h>

const int slaveSelectPin = 10; // Define Slave Select Pin

void setup() {
  Serial.begin(9600);
  pinMode(slaveSelectPin, OUTPUT);
  SPI.begin();
  SPI.setBitOrder(MSBFIRST); // Define Data Structure
  SPI.setDataMode(SPI_MODE1); // Define SPI Mode for CPOL = 0 and CPHA = 1
}

void loop() {
  unsigned int error;

  digitalWrite(slaveSelectPin, LOW); // Start Communication
  SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE1)); // Start SPI transaction
  SPI.transfer(0xA1); // Sending Address for Read (0x21 with R/W bit set to 1)
  error = SPI.transfer(0x00); // Read the Error Bits
  SPI.endTransaction(); // End SPI transaction
  digitalWrite(slaveSelectPin, HIGH); // End Communication

  Serial.println(error);
  delay(1000); // Add a delay between readings (adjust as needed)
}

found be searching with

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