problems with Spi.h

Hi,

we are having some problems using the Spi.h library.

what we try to do: it is for a small projekt, connecting 2 Arduinos with two NRF24l01 devices.

We are trying to include the Spi library with: “#include <Spi.h>”
Everything we get is:

17: error: no such file or directory In function ‘void setup()’:
In function ‘void loop()’:
Bad error line: -3

We tried it with #include <spi.h> …no change
We downloaded the Spi library file from Arduino.cc and basicly copied it everywhere…but it always told us the same mistake. Now we ran out of ideas, so we are asking for help.

THX for your time

What version of the Arduino IDE are you using?

and basicly copied it everywhere…

Where did you copy it to? What it did you copy?

it is the downloaded spi lirary…so the Spi.h, Spi.cpp and keywords.txt

i copied it in various folders: the arduino-0017/lib, arduino-0017/hardware/libraries/Ethernet/utility, the folders in between, the folder where the project itself is saved, in this I created a folder libraries an copied it there…we have just no idea what is the problem

In the arduino-0017 folder, you should have a hardware folder. In the hardware folder, you should have a libraries folder. In the libraries folder, you should have an spi folder. In that folder, you should have the keywords.txt file, the spi.cpp file, and the spi.h file.

I do not have this library, so I can not tell you for certain whether it should be spi.cpp or Spi.cpp, but case matters. Whatever case is used for the source and header files should also be use for the containing directory's name.

When you select the Sketch + Import Library menu items, does the spi library name appear in the list? If it does, you have the library installed in the right place. If not, you don't.

Of course, once you get it installed in the right place, you need to stop and restart the IDE.

THX - this worked

now I'm happy ::)

BTW, as of Arduino 0017, third-party libraries should not be installed in the hardware/ folder. Instead, use the "libraries" sub-folder of your Arduino sketchbook directory. This ensures that the libraries will stick around when you upgrade to a new version of Arduino.

See: http://arduino.cc/en/Guide/Environment#libraries

I have found several versions of the SPI Library.

Can you tell me where the best or official library is being held?

The one in the PlayGround under the /Code/ folder is incomplete.

We are having similar trouble with Spi.h library and wonder if it is because we are using the one from the Arduino playground. We have been able to get the libraries into the proper place so that they are being found and recognized, but now we are running into other errors.

Where are you finding your Spi.h files that are working? Is the one from the playground incomplete?

hi… i included the file successfully by copying the downloaded file into libraries folder of the arduino which has other folders like liquid crystal, EEPROM etc.

And include in the sketch by writing this code.

#include " Spi.h "


but i have other problems with the library.

If i read the SPCR register after initialization, i can read the correct data on serial monitor but reading SPDR always yields 0xFF value in spite of loading it with some other value.

in fact SPDR should contain the data need to be transmitted and it retains the data even after transmission. so reading it should show the value passed into Spi.transfer() function.
But i always read 0xFF value.

PLZ help me asap as i need to interface MCP2515 and i suspect that Spi.transfer() function is itself not working properly.

by the way the following is my code for testing the CAN controler in loopback mode.

i din find any probs with the code. if u find any PLZ help me out…

#include "Spi.h"
#define SCK 13
#define SO 12
#define SI 11
#define SS 10  

//opcodes

#define RESET 2
#define READ  0x03
#define WRITE 0x02

byte clr;
byte STATUS;
void setup()
{
  Serial.begin(9600); // SPI INITIALIZATION 
  pinMode (SCK,OUTPUT);
  pinMode (SO,OUTPUT);
  pinMode (SI, INPUT);
  pinMode (SS, OUTPUT);
  pinMode(RESET,OUTPUT);
  
  
  /* SPI interrupt disabled, SPI enabled, sends MSB first, MC is master,  
   clock polarity=0, clock phase=0(hence mode 0), SPI speed = 4MHz(fastest)*/
  
  SPCR = ( (1<<SPE)|(1<<MSTR)); // 0101 0000
  clr=SPSR;                                 
  clr=SPDR;

/* configure CAN by setting bit timing ( and hence baud rate at 1Mbps)
 1Bit=1 micro second.
 Let baud rate prescaler = 0
 Then TQ= 100ns
 i.e 1 bit = 10 TQ
 //sync seg= 1TQ, prog seg=2 TQ, PS1=3 TQ, PS2= 4TQ//
 also sampling is happening at 60% of the bit time.*/
 
digitalWrite(RESET,LOW); /* RESET CAN CONTROLLER*/
delay(10);
digitalWrite(RESET,HIGH);
delay(10);

digitalWrite(SS,LOW);
Spi.transfer(WRITE);
Spi.transfer(0x3F);// address of CANCTRL register of TXB0
Spi.transfer(0x90);// select Configuration mode for programming bit-time
digitalWrite(SS,HIGH);
delay(10);

digitalWrite(SS,LOW);
Spi.transfer(WRITE);
Spi.transfer(0x2A);// address of CNF1 register
Spi.transfer(0x80);//1000 0000- SJW= 3TQ, BRP=0
digitalWrite(SS,HIGH);
delay(10);

digitalWrite(SS,LOW);
Spi.transfer(WRITE);
Spi.transfer(0x29);// address of CNF2 register
Spi.transfer(0x91);// 1001 0001- sampling at sample point,prog seg= 2TQ, PS1= 3TQ
digitalWrite(SS,HIGH);
delay(10);

digitalWrite(SS,LOW);
Spi.transfer(WRITE);
Spi.transfer(0x28);// address of CNF3 register
Spi.transfer(0x03);// PS2= 4TQ
digitalWrite(SS,HIGH);
delay(10);



// initialize CAN
  
  delay(10); 
  digitalWrite(SS,LOW);
  Spi.transfer(WRITE);// write instruction
  Spi.transfer(0x3F);// address of CANCTRL register of TXB0
  Spi.transfer(0x50);// select loop back mode for testing
  digitalWrite(SS,HIGH);
  delay(10);
  
  digitalWrite(SS,LOW);
  Spi.transfer(WRITE);// write instruction
  Spi.transfer(0x6F);// address of CANCTRL register of RXB0
  Spi.transfer(0x50);// select loop back mode for testing 01010000
  digitalWrite(SS,HIGH);
  delay(10);
}


void loop()
{
  delay(10);
  digitalWrite(SS,LOW);
  Spi.transfer(READ);
  Spi.transfer(0x3E);// CANSTAT address of TXB0
  STATUS=Spi.transfer(0xFF); 
  digitalWrite(SS,HIGH);
  delay(10);
  Serial.println(STATUS, HEX);
  delay(1000);
 }

NOTE: i have initialized CAN but i am not transmitting any data… first i just want to test the READ, WRITE instructions. So i am reading registers of MCP2515. but all i am getting on serial monitor is 0xFF :frowning:

Hi, I could solve my problem. But got too busy to post here. I am sorry. the problem was the definition of SPI pins MOSI and MISO in my sketch. I had interchanged its functions. correcting that, the SPI worked fine. The communication between MCP2515 and ATmega is working.

Thanks :)