I am using the SPI protocol analyzer on WaveForms (using the Analog Discovery 2) and I'm getting weird results. I keep getting results that look like this:
*********************
Leftover bits: 2 0,
Leftover bits: 3 32,
Leftover bits: 2 0,
Leftover bits: 4 96,
Leftover bits: 5 248,
*********************
I am using an Arduino Uno to send the SPI data. The sketch is as follows:
********************************
#include <SPI.h>
unsigned long lastInterrupt = 0;
unsigned long thisInterrupt;
uint8_t Command = 173;
uint16_t Data = 52128;
void setup() {
SPI.begin();
pinMode(8, OUTPUT);
pinMode(2, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(2), Interr, FALLING);
SPI.beginTransaction(SPISettings(100000, MSBFIRST, SPI_MODE1));
}
void Interr() {
thisInterrupt = millis();
if ((thisInterrupt - lastInterrupt) > 500) {
digitalWrite(8, LOW);
SPI.transfer(Command);
SPI.transfer16(Data);
digitalWrite(8, HIGH);
}
lastInterrupt = thisInterrupt;
}
void loop() {}
********************************
I saw in another forum post that this "leftover bits" issue is caused when the active low cycle doesn't match up with the data transfer. However, I am confused why I am only getting leftover bits and no command or data bits. As well, the number of leftover bits does not add up to command bits + data bits, so where are the other bits going? I have attached a picture of my WaveForms settings. Could anyone help me with this issue? Or give me more insight on this issue? Is my CS pin going back to HIGH too early or too late? Please let me know if you need more information about the issue.