After some misunderstanding and head bashing I have managed to read SSI data from an absolute encoder using SPI. I had it working just bit banging it out switching a clock pin on and off. I wasn't great but by stealing ideas and some bits of code from this forum I got it working ok(ish).
The SPI examples I found here never worked for me so I started from scratch and now it works really well. No errors and a reading every 50ms(ish).
#include <SPI.h>
unsigned int receivedVal;
unsigned int receivedVal2;
unsigned int result;
int temp;
void setup() {
Serial.begin(115200);
SPI.begin();
delay(100);
}
void loop() {
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE3));
receivedVal = SPI.transfer(0xFF);
receivedVal2 = SPI.transfer(0xFF);
temp = bitRead(receivedVal, 6);
bitWrite(result, 12, temp);
temp = bitRead(receivedVal, 5);
bitWrite(result, 11, temp);
temp = bitRead(receivedVal, 4);
bitWrite(result, 10, temp);
temp = bitRead(receivedVal, 3);
bitWrite(result, 9, temp);
temp = bitRead(receivedVal, 2);
bitWrite(result, 8, temp);
temp = bitRead(receivedVal, 1);
bitWrite(result, 7, temp);
temp = bitRead(receivedVal, 0);
bitWrite(result, 6, temp);
temp = bitRead(receivedVal2, 7);
bitWrite(result, 5, temp);
temp = bitRead(receivedVal2, 6);
bitWrite(result, 4, temp);
temp = bitRead(receivedVal2, 5);
bitWrite(result, 3, temp);
temp = bitRead(receivedVal2, 4);
bitWrite(result, 2, temp);
temp = bitRead(receivedVal2, 3);
bitWrite(result, 1, temp);
temp = bitRead(receivedVal2, 2);
bitWrite(result, 0, temp);
float angle = result * 0.04395;
Serial.println(angle);
delay(50);
}
My problem is that I can't work out how to manipulate the bits from the two bytes to extract the relevant data. I resorted to using bitRead and bitWrite but I am sure there must be a better way.
Neither byte seems to be used entirely, bits 6 to 0 from the first byte and bits 7 to 2 from the second byte. I have spent time looking at all the bit manipulation commands and looked at examples but I just haven't managed to make it work.
The encoder is Kubler type 8.5873.5320.B301.S003
I have a Nano and I am interfacing through a SN75179BC line transceiver.
Any help with the bits would be appreciated.