mirf and sd using spi

I have tried to get the radio and card to work for days. Can someone PLEASE HELP ! Here is a sample

#include <SPI.h>
#include <SD.h>
#include <SPI.h>
#include <mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>

//boolean b = 0;
byte thisChar[16]; // incoming wireless data
// On the Ethernet Shield, CS is pin 4. Note that even if it's not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
const int chipSelect = SS;
int data[16];
File dataFile;

void setup()
{
Mirf.cePin = 8;
Mirf.csnPin = 7;

// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

Serial.print("Initializing SD card...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:

// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
while (1) ;
}
Serial.println("card initialized.");

// Open up the file we're going to log to!
dataFile = SD.open("datalog.txt", FILE_WRITE);
if (! dataFile) {
Serial.println("error opening datalog.txt");
// Wait forever since we cant write data
while (1) ;
}

delay(50);

Mirf.spi = &MirfHardwareSpi;

/*

  • Setup pins / SPI.
    */

Mirf.init();

/*

  • Configure reciving address.
    */

Mirf.setRADDR((byte *)"serv1");

/*

  • Set the payload length to sizeof(unsigned long) the
  • return type of millis().
  • NB: payload on client and server must be the same.
    */

Mirf.payload = sizeof(int);
data[Mirf.payload];
/*

  • Write channel and payload config then power up reciver.
    */

Mirf.config();

Serial.println("Listening...");
}
void loop()
{

delay(50);

data[Mirf.payload];

/*

  • If a packet has been recived.
  • isSending also restores listening mode when it
  • transitions from true to false.
    */
    // Mirf.send(data);

if(!Mirf.isSending() && Mirf.dataReady()){
Serial.println("Got packet");

//Mirf.send(data);
/*

  • Get load the packet into the buffer.
    */

Mirf.getData((byte *)&data);

Serial.println(thisChar[16]);
// make a string for assembling the data to log:
String dataString = "";

// read three sensors and append to the string:
for (int analogPin = 0; analogPin < 3; analogPin++) {
int sensor = analogRead(analogPin);
dataString += String(sensor);
if (analogPin < 2) {
dataString += ",";
}
}

dataFile.println(dataString);

// print to the serial port too:
Serial.println(dataString);

// The following line will 'save' the file to the SD card after every
// line of data - this will use more power and slow down how much data
// you can read but it's safer!
// If you want to speed up the system, remove the call to flush() and it
// will save the file only every 512 bytes - every time a sector on the
// SD card is filled with data.
dataFile.flush();

}
// Take 1 measurement every 500 milliseconds
delay(50);
}

Can someone show me a code any code with 2 or more working SPI devices and there library?

new1111111:
Can someone show me a code any code with 2 or more working SPI devices and there library?

#include <SPI.h>

#define RAM_CS 10              // Connected to 23LC512 SPI Ram
#define EXPANDER_CS 9      // Connected to MCP23S17  16bit SPI I/O Expander
#define EXPANDER_ADDRESS 0x40  // MCP23s17 address
#define EXPANDER_READ 1

void setup(){

digitalWrite(RAM_CS,HIGH);
digitalWrite(EXPANDER_CS,HIGH);
pinMode(RAM_CS,OUTPUT);
pinMode(EXPANDER_CS, OUTPUT);

SPI.begin(); // init SPI hardware
}

void loop(){
   // write byte to address 0 of SPI_RAM
   uint8_t byteread;
   uint16_t addr=0;

   digitalWrite(RAM_CS,LOW);
   byteread = SPI.transfer(0x02);                // write command
   byteread = SPI.transfer(highByte(addr)); // MSB addr
   byteread = SPI.transfer(lowByte(addr));  // LSB addr
   byteread = SPI.transfer(0);                     // data byte
   digitalWrite(RAM_CS,HIGH);

//Read byte at address =1
   addr = 1;
   digitalWrite(RAM_CS,LOW);                     // Start SPI Transaction with Ram
   byteread = SPI.transfer(0x03);                // Read command
   byteread = SPI.transfer(highByte(addr)); // MSB addr
   byteread = SPI.transfer(lowByte(addr));  // LSB addr
   byteread = SPI.transfer(0);                     // out bound byte is ignored, read byte is in byteread
   digitalWrite(RAM_CS,HIGH):                   // end SPI Transaction with RAM

// byteread contains data from address 0x0001 of SPIRAM (23LC512)

// working with the MCP23S17 is a little more complex, 
//    a Slave address and R/W must be sent as the first byte
//    a byte of address must be send next.   

// Write 0x07 to portA

   digitalWrite(EXPANDER_CS,LOW);
   byteread=SPI.transfer(EXPANDER_ADDRESS); 
   byteread = SPI.transfer(0x12);                        // register address for port A
   byteread = SPI.transfer(0x07);
   digitalWrite(EXPANDER_CS,HIGH);

// Read from Port B

   digitalWrite(EXPANDER_CS,LOW);
   byteread = SPI.transfer(EXPANDER_ADDRESS|EXPANDER_READ);  // set read mode
   byteread = SPI.transfer(0x13);                                                     // register address for Port B
   byteread = SPI.transfer(0);                                                          // byteread now contains portB value
   digitalWrite(Expander_CS,HIGH);  // all done.

This is a simple example of how to use SPI.

I rewrote SPI to allow interrupt driven multi block transfers it gets a lot more complicated. Attached is the header for my_SPI. if you can understand how to use it I can send you a copy of the library.

Chuck.


Check out my Kickstarter Project Memory Panes an expansion RAM Shield for Mega2560's. It adds 1MB of RAM for those projects where 8KB is not enough.

my_SPI.h (10 KB)

No joy radio still dead .I have tried almost everything.Power supply ,SPI setting, calling one device at a time , different devices and radio not working.If the SS is just the CE how come there is only one in the library?