Need Help Reading Data from Zettlex Inductive Encoder Using SPI

Hello.

I am trying to test this inductive ring encoder on an Arduino Uno, but so far I've only gotten zeros as output, so I'm worried that I'm doing something seriously wrong.

The model number of the encoder is INC-3-150-111001-SPI1-AFL1-24-AN
Also, here is the datasheet for this product line

Most of my reliance has been on page 29, showing the wires, and pages 43 and 45, showing the SPI information.

I'm not the most knowledgeable about SPI, but it's weird not seeing any sort of register address or MOSI being mentioned, so I'm wondering if my setup here in the code is okay. My biggest questions are about all the timing. I included some small delays trying to stick with the charts in the datasheet, but I don't know if those even help or are implemented right.

Right now, my main concern is just getting reasonable data from the encoder, since I'm pretty sure I know how to interpret the 11 position bits once I get them.

Any help with this would be appreciated.

Also, here is my most recent code below

#include <SPI.h>
#define SS  10
uint8_t readbyte[6];

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);  
  pinMode(SS, OUTPUT);
  digitalWrite(SS, HIGH);
  SPI.begin();
  SPI.setClockDivider(SPI_CLOCK_DIV32);
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE2);
  delayMicroseconds(100);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(SS, LOW);
   uint8_t val = 0x00;
  for (int k=0; k <= 5; k++){
    readbyte[k] = SPI.transfer(val);
    delayMicroseconds(5);
  }
  digitalWrite(SS, HIGH);


  for (int a = 0; a <= 5; a++){
    Serial.print(readbyte[a]);
  }

  Serial.println("");
  
  delayMicroseconds(30);
}

SPI is nothing to do with registers, its just a wire-protocol for exchanging bytes. Here the data only goes one
way so MOSI is not used. Any register addressing scheme you may have seen on other chips is a layer built on top of SPI's wire protocol.

Note that you need a negative going clock, and read data on the clock's falling edge. This means setting
the SPI hardware registers correctly for this mode. SPI has 4 modes depending on whether the clock is idle high or low, and whether the data is supposed to be read on rising or falling edge (note that if the data is clocked on
the falling edge, it should be read on the risgin edge and vice versa.)

I'm pretty sure I have the mode set correctly, since Mode 2 includes a high idle state and a falling edge capture. And I'm glad I don't need a MOSI wire involved or to include some address transfer.

But as a follow-up, I have some other questions about wiring and timing. Currently, the Clock A wire goes to pin 13 (the SPI clock) and Data A goes to the MISO (pin 12). But I don't know where the chip select should go on the encoder.

Also, I don't know if any of the timing stuff I included makes sense. The clock divider should drop the frequency to 500 kHz. Are the 5 microsecond delays between byte reads necessary in my code?

1 Like