ISR (SPI_STC_vect) firing too many times - 8bit LabView boolean array along MOSI

In LabView, I’m testing this SPI 8-bit signal loop, pretty much identical to:

http://www.ni.com/example/9398/en/

The LabView program acts as the master…the Arduino Mega is the slave

When I use a logic analyzer at the points right before the signal reaches my Mega SPI lines, everything looks fine and dandy (SS, SCK, MOSI all produce correct results.)

However, I am more than likely coding my ISR routine incorrectly to handle the capturing of the byte.

If I send the number “11” from LabView (which gets converted to LSB boolean array), the ISR (SPI_STC_vect) in my Arduino program fires off a couple hundred times.

volatile boolean process_it;
char buff[10];
volatile byte spot;

// Here's the code for the Setup:

void setup() {
  Serial.begin(115200);
  Serial.println("Begin transmissions, Rotundra!");
  pinMode(MISO, OUTPUT);
  SPCR |= bit(SPE);
  SPCR |= bit(SPIE);
  //SPI.attachInterrupt();
}

// Here's the Loop:

void loop() {
  valuesSPI();
  delay(20);
}

// Here's the 'valuesSPI()' and 'ISR(SPI_STC_vect)' functions:

void valuesSPI() {
  if (process_it) {
    buff[spot] = 0;
    spot = 0;
    process_it = false;
}

ISR (SPI_STC_vect) {
  byte b = SPDR;
  Serial.println(b);
  if (spot < 11) {buff[spot++] = b;}
  else {process_it = true;}
}

I receive a ton of serial prints for the byte (I verify from the analyzer that only 8 bits get sent, yet printing ‘b’ doesn’t verify that.) I want to know how to capture the 1 byte from LabView, process it correctly, and print it. I did not use a Reverse Array in LabView, but at best I should be getting larger results up to 256 (just to confirm I’m not reversing the LSB order.) But even that is not occurring.

The byte should have bits containing number values ranging from 1-20.

I am very new to all this, so please go into detail if you have to.

I attached an .txt to show you the ‘Serial.println(b)’ output (I apologize for the length.)

Example Data SPI.txt (9.36 KB)

Don't put any Serial.print()s into an ISR. Do that in loop() after the ISR has completed.

...R

I took out the prints in ISR, put them in valuesSPI(). Rewrote the 2 functions:

void valuesSPI() {
    if (!process_it) {
      Serial.print("buffer: ");
      Serial.println(buff[0]);
      buff[0] = 0;
      process_it = true;
    }
}

ISR (SPI_STC_vect) {
  byte b = SPDR;
  if (process_it) {
    buff[0] = b;
    process_it = false;
  }
}

Prints out gibberish.

lennon-pledge:
Prints out gibberish.

If you want help please post the complete program. I am not going to try and patch stuff together and introduce more errors.

And post an example of the actual output and what it should be.

…R