Can't connect PST-360 SPI angle sensor to ESP32 s3

Hi,

I need your help :(. I'm trying to get angle values from PST-360 angle sensor using my Banana Pi BPI-Leaf-S3 (ESP32 S3 development board). I've found a thread (Getting 0 values from a rotary position sensor - SOLVED!) where guys managed to connect to Arduino UNO R3.
I've took the source code that was tagged as working and made small corrections (because I'm not using MOSFET in my case).
Unfortunately, I don't get any response from my PST-360 device. Currently, I'm stuck in a corner. Maybe someone could give me advice on how to move forward.

Wiring diagram:

#include <Arduino.h>
#include <SPI.h>

const uint8_t CS_PIN = 10;

void setup() {
  Serial.begin(9600);
  while (!Serial.available());

  Serial.println(MOSI); // Black 11
  Serial.println(MISO); // Black R10 13
  Serial.println(SCK); // Grey 12
  Serial.println(SS); //CS White 10

  pinMode(CS_PIN, OUTPUT);
  digitalWrite(CS_PIN, HIGH); 
  SPI.begin();
  delay(20);
}

void loop() {
  /*A data frame consists of 10 bytes:
    • 2 start bytes (AAh followed by FFh)
    • 2 data bytes (DATA16 – most significant byte first)
    • 2 inverted data bytes (/DATA16 – most significant byte first)
    • 4 all-Hi bytes
  */
  uint8_t data[10] = {0};
  int index = 0;

  //min time between each bit transfer is 7 microseconds so set to 125kHz which is the lowest
  SPI.beginTransaction(SPISettings(125000, MSBFIRST, SPI_MODE1));   

  //Start transaction
  digitalWrite(CS_PIN, LOW);
  delayMicroseconds(20);
  
  //Send start byte
  data[index++] = SPI.transfer(0xAA);
  delayMicroseconds(50);

  //Send and receive data bytes
  for(uint8_t i = 1; i < 10; i++){
    data[index++] = SPI.transfer(0xFF); 
    delayMicroseconds(40);
  }
  
  //End transaction
  digitalWrite(CS_PIN, HIGH);
  SPI.endTransaction();

  //Extract and calculate angle
  uint16_t data_bytes = (data[2] << 8) | data[3];  // Combine two bytes
  uint16_t first14 = data_bytes >> 2; // Extract first 14 bits
  float value = (float)(first14 / 16384.0);  // Divide by 2^14 and multiply by 360 to get degrees
  float angle = (value - 0.1)/(0.9 - 0.1) * 360;
 
  //Serial.println(angle);
  for (int i = 0; i < 10; i++) 
  Serial.print(data[i], HEX);
  Serial.println();
  Serial.println(angle);
  delay(100);
}

Results from Logic Analyser:

Command description from documentation(https://www.piher.net/wp-content/uploads/Piher_-Serial_Protocol_V01.pdf):

I'm just a hobby maker not a professional, what I'm missing there? Thank you in advance.

The problem is solved. After many double and triple checks, I found that my resistor was connected to MISO pin, not MOSI, and it's not right when you want to use 3-wire SPI connection. I hope that it will help someone in the feature.

1 Like

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