Trouble with SPI.h SD.h

I’m usually not one for posting and asking for help, but i have been Googling and Googling for hour and I am pulling up blanks.

All i am trying to do is run the simple SD ReadWrite function. but i cannot get it to upload to the Arduino no matter what i have found and tried its still failing so I’m tuning to the forums for help, knowing my luck its something stupidly obvious.

Anyway here we go, this is what I’m trying to upload;

/*
  SD card read/write

 This example shows how to read and write data to and from an SD card file
 The circuit:
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4

 created   Nov 2010
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe

 This example code is in the public domain.

 */

#include <SPI.h>
#include <SD.h>

File myFile;

void setup()
{
  // 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...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
  pinMode(10, OUTPUT);

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop()
{
  // nothing happens after setup
}

and these are the errors I am receiving;

Arduino: 1.6.1 (Windows 8.1), Board: "Arduino Uno"

Build options changed, rebuilding all

C:\Program Files (x86)\Arduino\libraries\SD\src\utility\Sd2Card.cpp:27:8: error: 'SPISettings' does not name a type

 static SPISettings settings;

        ^

C:\Program Files (x86)\Arduino\libraries\SD\src\utility\Sd2Card.cpp: In member function 'void Sd2Card::chipSelectHigh()':

C:\Program Files (x86)\Arduino\libraries\SD\src\utility\Sd2Card.cpp:167:9: error: 'class SPIClass' has no member named 'endTransaction'

     SPI.endTransaction();

         ^

C:\Program Files (x86)\Arduino\libraries\SD\src\utility\Sd2Card.cpp: In member function 'void Sd2Card::chipSelectLow()':

C:\Program Files (x86)\Arduino\libraries\SD\src\utility\Sd2Card.cpp:176:9: error: 'class SPIClass' has no member named 'beginTransaction'

     SPI.beginTransaction(settings);

         ^

C:\Program Files (x86)\Arduino\libraries\SD\src\utility\Sd2Card.cpp:176:26: error: 'settings' was not declared in this scope

     SPI.beginTransaction(settings);

                          ^

C:\Program Files (x86)\Arduino\libraries\SD\src\utility\Sd2Card.cpp: In member function 'uint8_t Sd2Card::init(uint8_t, uint8_t)':

C:\Program Files (x86)\Arduino\libraries\SD\src\utility\Sd2Card.cpp:269:3: error: 'settings' was not declared in this scope

   settings = SPISettings(250000, MSBFIRST, SPI_MODE0);

   ^

C:\Program Files (x86)\Arduino\libraries\SD\src\utility\Sd2Card.cpp:269:53: error: 'SPISettings' was not declared in this scope

   settings = SPISettings(250000, MSBFIRST, SPI_MODE0);

                                                     ^

C:\Program Files (x86)\Arduino\libraries\SD\src\utility\Sd2Card.cpp:275:7: error: 'class SPIClass' has no member named 'beginTransaction'

   SPI.beginTransaction(settings);

       ^

C:\Program Files (x86)\Arduino\libraries\SD\src\utility\Sd2Card.cpp:279:7: error: 'class SPIClass' has no member named 'endTransaction'

   SPI.endTransaction();

       ^

C:\Program Files (x86)\Arduino\libraries\SD\src\utility\Sd2Card.cpp: In member function 'uint8_t Sd2Card::setSckRate(uint8_t)':

C:\Program Files (x86)\Arduino\libraries\SD\src\utility\Sd2Card.cpp:518:14: error: 'settings' was not declared in this scope

     case 0:  settings = SPISettings(25000000, MSBFIRST, SPI_MODE0); break;

              ^

C:\Program Files (x86)\Arduino\libraries\SD\src\utility\Sd2Card.cpp:518:66: error: 'SPISettings' was not declared in this scope

     case 0:  settings = SPISettings(25000000, MSBFIRST, SPI_MODE0); break;

                                                                  ^

Error compiling.

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

This level of debugging in this is well and truly out of my skill level … And then some :confused: .

Finally I’m trying to interface a 2GB SD card via a shield made from this site
http://www.xappsoftware.com/wordpress/2012/07/12/how-to-interface-a-sd-card-to-an-arduino-board/

and i am using
Pin 13 - CLK
Pin 12 - MISO
Pin 11 - MOSI
&
PIN 10 - CS

if anyone can help even if its pointing out the useless mistake i have made and cant figure out i would be muchly appreciated.

Looks like you are using a new version of the SD library (IDE v1.6.x) with an older version of the SPI library. The beginTransaction function is new, starting with v1.6.x.

I can't tell you how that happened.

It appears you have an old version of the SPI.h library somewhere. The old version is being used instead of the new 1.6.1 version.

The old version may be here (bill will be replaced by your user name).

C:\Users\bill\Documents\Arduino\libraries\SPI

I copied the 1.0.6 version to this location and got similar errors.

Arduino: 1.6.1 (Windows 7), Board: “Arduino Uno”

Build options changed, rebuilding all

D:\arduino-1.6.1\libraries\SD\src\utility\Sd2Card.cpp:27:8: error: ‘SPISettings’ does not name a type

static SPISettings settings;

^

D:\arduino-1.6.1\libraries\SD\src\utility\Sd2Card.cpp: In member function ‘void Sd2Card::chipSelectHigh()’:

D:\arduino-1.6.1\libraries\SD\src\utility\Sd2Card.cpp:167:9: error: ‘class SPIClass’ has no member named ‘endTransaction’

SPI.endTransaction();

^

D:\arduino-1.6.1\libraries\SD\src\utility\Sd2Card.cpp: In member function ‘void Sd2Card::chipSelectLow()’:

D:\arduino-1.6.1\libraries\SD\src\utility\Sd2Card.cpp:176:9: error: ‘class SPIClass’ has no member named ‘beginTransaction’

SPI.beginTransaction(settings);

^

D:\arduino-1.6.1\libraries\SD\src\utility\Sd2Card.cpp:176:26: error: ‘settings’ was not declared in this scope

SPI.beginTransaction(settings);

^

D:\arduino-1.6.1\libraries\SD\src\utility\Sd2Card.cpp: In member function ‘uint8_t Sd2Card::init(uint8_t, uint8_t)’:

D:\arduino-1.6.1\libraries\SD\src\utility\Sd2Card.cpp:269:3: error: ‘settings’ was not declared in this scope

settings = SPISettings(250000, MSBFIRST, SPI_MODE0);

^

D:\arduino-1.6.1\libraries\SD\src\utility\Sd2Card.cpp:269:53: error: ‘SPISettings’ was not declared in this scope

settings = SPISettings(250000, MSBFIRST, SPI_MODE0);

^

D:\arduino-1.6.1\libraries\SD\src\utility\Sd2Card.cpp:275:7: error: ‘class SPIClass’ has no member named ‘beginTransaction’

SPI.beginTransaction(settings);

^

D:\arduino-1.6.1\libraries\SD\src\utility\Sd2Card.cpp:279:7: error: ‘class SPIClass’ has no member named ‘endTransaction’

SPI.endTransaction();

^

D:\arduino-1.6.1\libraries\SD\src\utility\Sd2Card.cpp: In member function ‘uint8_t Sd2Card::setSckRate(uint8_t)’:

D:\arduino-1.6.1\libraries\SD\src\utility\Sd2Card.cpp:518:14: error: ‘settings’ was not declared in this scope

case 0: settings = SPISettings(25000000, MSBFIRST, SPI_MODE0); break;

^

D:\arduino-1.6.1\libraries\SD\src\utility\Sd2Card.cpp:518:66: error: ‘SPISettings’ was not declared in this scope

case 0: settings = SPISettings(25000000, MSBFIRST, SPI_MODE0); break;

^

Error compiling.

This report would have more information with
“Show verbose output during compilation”
enabled in File > Preferences.

WOW lol !

THANK YOU BOTH SOO MUCH !!!

see i said it would be something silly and obvious.
again thank you so much.

Hi guys. I'm having a similar issue to the poster. Can you tell me where to find the updated SPI.h library. Everywhere I look I can't find anything.

You should have an updated SPI library that came with your Arduino 1.6.x IDE install. Just find the old one and delete it and your code should compile fine.

jasp05:
Hi guys. I'm having a similar issue to the poster. Can you tell me where to find the updated SPI.h library. Everywhere I look I can't find anything.

Just have the latest Arduino IDE

can anyone upload old version of spi library

Here it is from 1.0.5

keywords.txt (831 Bytes)

SPI.cpp (1.69 KB)

SPI.h (1.57 KB)

And from 1.6.5-r5, apparently buried in the /libraries/wifi/src/uility folder,
I don’t know how the IDE knows to look for it there.

spi_drv.cpp (11.8 KB)

spi_drv.h (3.02 KB)

thanks for the help @CrossRoads, but this is spi version 2.1 and it’s the current version.