Im trying to read values from an SPI encoder. urrently i only have my Logic analyser connected. Thats the reason ther is nothing on MISO but he clock should be genrated by the Master, right? Maybe there is also an issue with my SPI code since it is my first time working with SPI...
Here is my code:
#include <SPI.h>
const int encoderNCS = 10; // Chip select (slave select) pin for the encoder
const int encoderMISO = 12; // MISO pin of the encoder
const int encoderMOSI = 11; // MOSI pin of the encoder
const int encoderSCK = 13; // SCK pin of the encoder
// Reading command: 00001100000000111111
byte command[] = {B0, B0, B0, B0, B1, B1, B0, B0, B0, B0, B0, B0, B0, B0, B1, B1, B1, B1, B1, B1}; //read command converted to bytes variable
byte receivedBit[] = {B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0}; //initialize storage bytes
void setup() {
Serial.begin(9600);
SPI.begin();
pinMode(encoderNCS, OUTPUT);
digitalWrite(encoderNCS, HIGH); // Set NCS (CS) high initially
}
void loop() {
// Enable the encoder by pulling NCS low
digitalWrite(encoderNCS, LOW);
delayMicroseconds(350); // At least 350ns between NCS falling edge and SCK rising edge
SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE1)); // CPOL=0, CPHA=1
// Simultaneously send and receive data
for (int i = 0; i < 20; i++) {
receivedBit[i] = SPI.transfer(command[i]);
Serial.print(command[i]);
}
SPI.endTransaction();
Serial.println(); // Print a new line after all 20 bits are received
// Disable the encoder by pulling NCS high with sufficient high time
digitalWrite(encoderNCS, HIGH);
delayMicroseconds(350); // High time of NCS between two transmissions at least 350ns
}
Output of my logic analyser SCK is connected with Chanel0:
