SPI problem with adafruit SD shield & Mega

If you define MEGA_SOFT_SPI nonzero, software SPI will be used on ATmega1280 and ATmega2560 processors. You can then use the Adafruit Data Logging Shield with no hardware mods. No extra wires connecting the shield SPI pins to the Mega hardware SPI pins 50, 51, 52, 53. You must use pin 10 as chip select in your begin/init call.

Software SPI is highly optimized and runs fast enough for most data logging applications. I tested an Adafruit Data Logging Shield with a Mega 2560.

I ran the SdFat benchmark sketch with two mods. I set MEGA_SOFT_SPI = 1 and used pin 10 for chip select in the init call. The result was:

Type any character to start
Free RAM: 6757
Type is FAT16
File size 5MB
Starting write test. Please wait up to a minute
Write 81.18 KB/sec

Starting read test. Please wait up to a minute
Read 102.04 KB/sec
Done

If you wish to use the hardware SPI pins don't modify SdFat or anything else like SPI.h. Just connect MISO, MOSI, and CLK on the shield to the mega pins 50, 51, and 52.

You can then use any pin for chip select. If you run a wire to Slave Select, SS, on the Mega use pin 53 in your begin/init call. If you don't run an extra wire and use the Adafruit pin, use pin 10 in the begin/init call.

Hardware avr SPI uses 5 pins. MISO, MOSI, CLK, SS, and chip select. SdFat sets SS, Slave Select, to an output even if it is not used as chip select since the avr hardware SPI will not function in master mode if SS is an input and goes low.