SPI playing "ping pong"

I’m trying to do some communicating between the Raspberry PI and the Arduino.

I’m using Nick Gammon’s excellent page on Arduino SPI and Gordon Henderson’s also-excellent WiringPI, which implements Wiring on a PI, along with his SPI library.

Examples for Gordon’s PI SPI library are sparse, but following one of the examples I’ve now got this on the PI:

#include <stdio.h>
#include <inttypes.h> // provides uint8_t etc
#include <wiringPi.h>
#include <wiringPiSPI.h>

void sendSPI (void);


int main (void)
{   
    wiringPiSetup();
	wiringPiSPISetup(1, 500000);
    sendSPI();
    return(0); 
}  


void sendSPI (void)
{
uint8_t a[] = {'H'};
uint8_t b[] = {'\n'};
wiringPiSPIDataRW(1,a,1);
wiringPiSPIDataRW(1,b,1);
    
uint8_t p[] = {'H','E','L','L','O','\n'};
    while (1){
       wiringPiSPIDataRW(1,p,6);
        delayMicroseconds(1);  // 1 seconds delay 
    }
}

And this on the Arduino:

#include <SPI.h>

char buf [100];
volatile byte pos;
volatile boolean process_it;

void setup (void)
{
  Serial.begin (115200);   // debugging

  // have to send on master in, *slave out*
  pinMode(MISO, OUTPUT);
  
  // turn on SPI in slave mode
  SPCR |= _BV(SPE);
  
  // get ready for an interrupt 
  pos = 0;   // buffer empty
  process_it = false;

  // now turn on interrupts
  SPI.attachInterrupt();

}  // end of setup


// SPI interrupt routine
ISR (SPI_STC_vect)
{
byte c = SPDR;  // grab byte from SPI Data Register
  
  // add to buffer if room
  if (pos < sizeof buf)
    {
    buf [pos++] = c;
    
    // example: newline means time to process buffer
    if (c == '\n')
      process_it = true;
      
    }  // end of room available
}  // end of interrupt routine SPI_STC_vect

// main loop - wait for flag set in interrupt routine
void loop (void)
{
  if (process_it)
    {
    buf [pos] = 0;  
    Serial.println (buf);
    pos = 0;
    process_it = false;
    }  // end of flag set
    
}  // end of loop

Nothing happens on the Arduino serial monitor, so I plugged in my logic analyzer and saw this:

Eh?! What’s happening here?!

You’ll notice I first of all run
wiringPiSPIDataRW(1,a,1);
wiringPiSPIDataRW(1,b,1);

before sending it into a loop. This is because I know that the Arduino receiving code is waiting for separate “triggers”, rather than the “burst” I’m sending it. Either way, what I can’t figure out after several long, long nights is how/why it seems to be doing this “cyclical” ping pong. I’ve tried slower speeds, faster speeds, I’ve tried wiringPiSPIDataRW(1,p,7); and wiringPiSPIDataRW(1,p,5);. Why is the Arduino even responding with what I sent it just before?!

Here’s more data. No idea how to get this table to line up. Sorry!

Time (s)	Packet ID	MOSI	MISO
0		                 H	\n
0.000097		\n	H
0.000196		H	\n
0.000215		E	H
0.000233		L	E
0.000252		L	L
0.00027		O	L
0.000289		\n	O
0.0004		        \n	\n
0.000419		H	\n
0.000437		E	H
0.000456		L	E
0.000474		L	L
0.000492		O	L
0.000615		\n	O
0.000634		\n	\n
0.000652		H	\n
0.000671		E	H
0.000689		L	E
0.000708		L	L
0.000799		O	L
0.000818		\n	O
0.000836		\n	\n
0.000855		H	\n
0.000873		E	H
0.000892		L	E
0.000996		L	L
0.001014		O	L
0.001032		\n	O
0.001051		\n	\n
0.001069		H	\n
0.001088		E	H
0.001176		L	E
0.001194		L	L
0.001212		O	L
0.001231		\n	O

Code goes in code tags. Questions do not.