Does this work

Below is a modified example from Gammon's code.
Just wanna know if this works, to test if an spi device is hooked up correctly.

#include <SPI.h>


void setup (void)
{

  Serial.begin(9600);
  digitalWrite(SS, HIGH);  // ensure SS stays high for now
  // Put SCK, MOSI, SS pins into output mode
  // also put SCK, MOSI into LOW state, and SS into HIGH state.
  // Then put SPI hardware into Master mode and turn SPI on
  SPI.begin ();

  // Slow down the master a bit
  SPI.setClockDivider(SPI_CLOCK_DIV8);
  
}  // end of setup


void loop (void)
{

  char c;

  // enable Slave Select
  digitalWrite(SS, LOW);    // SS is pin 10

SPI.transfer (0xCD);  // are you there?
byte x = SPI.transfer (0); // get response

if (x == 0xEF)
  {
  Serial.println("SPI correctly hooked up");  // prints hello with ending line break
  }

  // disable Slave Select
  digitalWrite(SS, HIGH);

  delay (1000);  // 1 seconds delay 
}  // end of loop

You need to know that your device will respond with an 0xef when you send it an 0xce, most devices will not respond like this.

You know a better way?

Send the device something it actually expects, and check the return for the predicted value. Studying the data sheet for the device is the first step.

-br

Tyger:
You know a better way?

Basically there is no generic way of telling if an SPI device is connected correctly.

Ok, can you tell me how to get the output to serial when i send something?

Ok, can you tell me how to get the output to serial when i send something?

Not without a lot more context. What are you sending? To what? From what?

Sorry, i mean now it sends 0xCD true SPI to the slave and if it gets 0xEF back it sends a serial message.
Now i want to send 0xCD true SPI to the slave, and i want to send the respons from the slave as a serial message so i can check the output.

Edit: Never mind, did it like this:
byte x = SPI.transfer (0); // get response

Serial.println(x); // prints hello with ending line break

Serial.println(x); // prints hello with ending line break

I think you will find it does not print hello.

indeed i screwed up

Sorry for the dubble post, i used gammons example with a command below, but i just wanna check if this is correct or my wiring is wrong.

// Written by Nick Gammon
// April 2011


#include <SPI.h>
#include "pins_arduino.h"

void setup (void)
{
  Serial.begin (115200);
  Serial.println ();
  
  digitalWrite(SS, HIGH);  // ensure SS stays high for now

  // Put SCK, MOSI, SS pins into output mode
  // also put SCK, MOSI into LOW state, and SS into HIGH state.
  // Then put SPI hardware into Master mode and turn SPI on
  SPI.begin ();

  // Slow down the master a bit
  SPI.setClockDivider(SPI_CLOCK_DIV8);
  
}  // end of setup

byte transferAndWait (const byte what)
{
  byte a = SPI.transfer (what);
  delayMicroseconds (20);
  return a;
} // end of transferAndWait

void loop (void)
{

  byte a, b, c, d;
  
  // enable Slave Select
  digitalWrite(SS, LOW);    

  transferAndWait ('0x0000');  // add command
  transferAndWait (10);
  a = transferAndWait (17);
  b = transferAndWait (33);
  c = transferAndWait (42);
  d = transferAndWait (0);

  // disable Slave Select
  digitalWrite(SS, HIGH);

  Serial.println ("Adding results:");
  Serial.println (a, DEC);
  Serial.println (b, DEC);
  Serial.println (c, DEC);
  Serial.println (d, DEC);
  
  // enable Slave Select
  digitalWrite(SS, LOW);   

  transferAndWait ('s');  // subtract command
  transferAndWait (10);
  a = transferAndWait (17);
  b = transferAndWait (33);
  c = transferAndWait (42);
  d = transferAndWait (0);

  // disable Slave Select
  digitalWrite(SS, HIGH);

  Serial.println ("Subtracting results:");
  Serial.println (a, DEC);
  Serial.println (b, DEC);
  Serial.println (c, DEC);
  Serial.println (d, DEC);
  
  delay (1000);  // 1 second delay 
}  // end of loop
  transferAndWait ('0x0000');  // add command

Why is that value in quotes?

Just wanna know if this works, to test if an spi device is hooked up correctly.

Did you go to mouser and buy a "generic SPI device"? Or do you have some specific SPI device in mind?

Im trying to hook up this http://ww1.microchip.com/downloads/en/devicedoc/70590c.pdf
And im a noob at arduino coding, did not notice that.

First off the device is a 3V3 device, so are you powering it with this voltage?
What have you done about the signals from the arduino, these are 5V and will need converting to 3V3.
This is a complex chip, it uses 16 bit words to communicate. The arduino SPI uses 8 bits so you have to use two transfers to get anything into the chip. Page 42 shows a register map with a value on power up or reset shown in the last column. I would try and read these and see if you get the same values.
Page 18 tells you what commands to send to read each register.

It also says:-

In general, MRF49XA registers are read only. Hence the chip status can only be read by the Status Read Register. During write, only appropriate byte is written to the desired register. It is not desired to read/write all registers and there is no way to read back the register.

So your technique of writing something and reading it back is not going to work.

Power and wiring is no problem for me, its the coding that is my problem.