PROBLEM: SSI absolute encoder and MEGA arduino

Hello everyone,

This is the first time I've used the arduino forum, so I'm sorry in advance if I'm listing my topic incorrectly.

I've been trying to get an SSi distance sensor to work with a MEGA arduino for a while now. The sensor is as follows:

To retrieve its data I use the CLK- and DATA- port with this program:

#define DATA_PIN 3

void setup() {

  pinMode(CLOCK_PIN, OUTPUT);
  pinMode(DATA_PIN, INPUT);
  Serial.begin(9600);

}

void loop() {

  uint32_t data = 0;
  
  for (int i = 0; i < 24; i++) {
    digitalWrite(CLOCK_PIN, HIGH);
    delayMicroseconds(1);
    digitalWrite(CLOCK_PIN, LOW);
    delayMicroseconds(1);
    data = (data << 1) | digitalRead(DATA_PIN);
  }

  Serial.println(data);

  delay(100);
}


When I retrieve my SSI frames everything is fine of course the short distances but when I exceed 2 meters which is half the distance of my sensor which is 4, I get erroneous values in fact it's as if I came back to my first values, moreover my value becomes very unstable once I exceed 2 meters. I'm stuck and feel like I'm missing a bit of information.

If anyone knows what the problem is, I'd be very grateful for any help. Thanks in advance.

Where in your code to you set the encoder so it will give you absolute distance values instead of working like a regular encoder? I don't see any hint of an attempt.

Thank you for your reply. Basically it's thanks to this loop:

  for (int i = 0; i < 24; i++) {
    digitalWrite(CLOCK_PIN, HIGH);
    delayMicroseconds(1);
    digitalWrite(CLOCK_PIN, LOW);
    delayMicroseconds(1);
    data = (data << 1) | digitalRead(DATA_PIN);
  }

I start a 24 bit safe clock, during the 24 iterations of my clock I will look at the state of my data port which gives me a high state or a low state which allows me to have a binary message on 24 bit which is the absolute position of my encoder.