Raspberry Pi (master) using spidev. Send array via SPI to Arduino UNO

Hello everyone,

I am trying to test if SPI is working. I want to send an array containing 4 integer elements from Pi to Arduino UNO and print the array on the Arduino side to make sure I get the values from the register. However, at the moment im not getting any output. I have attached my code below:

Raspberry Pi (master) code:

import spidev

import time

spi=spidev.SpiDev()

spi.open(0,0)

spi.max_speed_hz = 125000

to_send = [10, 20, 30, 40]

spi.xfer(to_send)

spi.close()

Arduino Slave Code

#include <SPI.h>
void setup() {

Serial.begin (125000); // debugging

// turn on SPI in slave mode

SPCR |= bit (SPE);

// have to send on master in, slave out

pinMode(MISO, OUTPUT);

// now turn on interrupts

SPI.attachInterrupt();

}

// SPI interrupt routine

ISR (SPI_STC_vect) {

int c = SPDR;

Serial.println(c); }

void loop() {}

A few suggestions, start by posting the schematic, a lot of problems are traced back to mistooks in the design. I would suggest you get one of the inexpensive 8 channel USB logic analyzers such as Saleae or a China ripoff. This will allow you to debug the SPI interface easily. If you are not familiar with logic analyzers spend a few evenings playing with it, once you understand it it is much better then a scope when working on communications. Try these links for some information; Basics of the SPI Communication Protocol
SPI Tutorial – Serial Peripheral Interface Bus Protocol Basics
You should get the cookbooks for both controllers and get a good understanding of how they work and how the hardware is configured. Remember the KISS principle, Keep It Simple and Slow.