Arduino Mega SPI Pin map

Hello,
A few things.
I realise the pinout for Duemilanove and Mega are different, is there a Mega specific library?
The LCD shield works with my mega but SPI does’nt, infact i’ve checked all pins and apart from pin 13 CLK nothing else responds, more specifically i want to use it with the Mirf Library, i have one Duemilanove with nrf24l01 and a Mega with nrf24l01, the duemilanove works fine but the mega will not do SPI, the Mega is only days old and apears to function ok i think it’s plain and simple down to software and pin mapping, which for today is beyond me
any help to shed light on this is greatly apreciated
Thanks

See this thread:- http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1251780678

Thanks Mike,

Some things are happening, this is running on a Duemilanove and sends 1 byte every second.

#include <Spi.h>
#include <mirf.h>
#include <nRF24L01.h>

byte data = 128;
int ledPin =  8; 
void setup()
{
//  Serial.begin(9600);
    pinMode(ledPin, OUTPUT); 

  Mirf.init();
  Mirf.setRADDR((byte *)"serv1");
  Mirf.payload = 1;
  Mirf.config();
}

void loop()
{
  byte data[Mirf.payload];
  Mirf.setTADDR((byte *)"clie1");
  Mirf.send(data);
  while(Mirf.isSending())
  {
    delay(100);
  }
  while(!Mirf.rxFifoEmpty());
  digitalWrite(ledPin, HIGH);  
  delay(50);               
  digitalWrite(ledPin, LOW);   
  delay(950);           

}

This code is running on a Mega1280 and recieves a byte and echo’s it to serial.

#include <Spi.h>
#include <mirf.h>
#include <nRF24L01.h>

void setup()
{
  Serial.begin(9600);
  Mirf.cePin = 49;
  Mirf.csnPin = 53;
  Mirf.init();
  Mirf.setRADDR((byte *)"clie1");
  Mirf.setTADDR((byte *)"serv1");
  Mirf.payload = 1;
  Mirf.config();
  Serial.println("Beginning ... "); 

}

void loop(){
    byte data = 0;
  if(Mirf.dataReady())
  {
    Mirf.getData((byte *) data);
    Serial.println(data, DEC);
  }
  delay(10);
}

In order to get it to work on the mega i have to edit the #defines in the SPI library to
#define SCK_PIN 52
#define MISO_PIN 50
#define MOSI_PIN 51
#define SS_PIN 53

this is a pain when using two different arduino’s,
Does anyone know how “If def’s” work and how i could ad an if def to the spi library so that all i need to do is add #ifndef USE_MEGA to my code and it will use the correct pin assignments
BTW. with the code above im supposedly sending value 128 but im recieving data = 0, this is a small thing, i want to get the spi lib done first so i dont have to keep editing it

Thanks in advance

You can use the pre-defined values for the chip. For instance,

if defined(AVR_ATmega168) || defined(AVR_ATmega328)

// place your 168/328 specific stuff here...

endif

if defined(AVR_ATmega128) || defined(AVR_ATmega1280)

// your Mega board specific stuff here...

endif

Providing you set the board type correctly (Tools/Board menu) then it will work correctly for you.

Sorry, in the example, it should be AVR_ATmega328P

Thanks steve, i think i understand, does this define go in the SPI.h, im at work now but will try when i get home
Thanks

[edit]
At home now, tested, great, does exactly what i wanted it to, thanks again
[/edit]

/*
  Spi.h - SPI library
  Copyright (c) 2008 Cam Thompson.
  Author: Cam Thompson, Micromega Corporation, <www.micromegacorp.com>
  Version: December 15, 2008

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#ifndef Spi_h
#define Spi_h

#include "WProgram.h"

#if  defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
  #define SCK_PIN   13
  #define MISO_PIN  12
  #define MOSI_PIN  11
  #define SS_PIN    10
#endif

#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__)
  #define SCK_PIN   52
  #define MISO_PIN  50 
  #define MOSI_PIN  51
  #define SS_PIN    53
#endif



class SPI
{
  public:
    SPI(void);
    void mode(byte);
    byte transfer(byte);
    byte transfer(byte, byte);
};

extern SPI Spi;

#endif