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
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
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
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.