Hello all,
Long story short, I want to control 2 servos on timer1, which means pins 9 and 10. Therefore, I have to move the SS from pin 10 to pin 3 - reason is because it is the only open pin I have. Im trying to figure out why my main code won't compile. Here is the set up. I have a main .ino file - LIFA_Base_Ethernet - which calls SPI_LIFA.h - SPI with the SS pin changed via #include "SPI_LIFA.h". the main code and SPI_LIFA.cpp/h are in the same folder and they are added to the same Arduino IDE.
Below is the error codes and SPI_LIFA files. The only changes I made were in the .cpp. Instead of having things for to SS, I changed it to 3.
One more thing... I am using an Arduino Ethernet and I'm communicating via Ethernet, would that mean I must also make a custom Ethernet library...? I'm not the best with communication proto calls but I think the ethernet library uses SPI, so that would make sense that I have to.
EDIT:
I know Ethernet uses SPI, just went through the library and the file w5100.h calls the SPI library. Is there a way to single that file out and put it with the rest of my code or will I have to copy over the entire library? I ask because I'm trying to keep all the files associated with LIFA_Base in one folder.
Thanks,
Matt
Errors.
C:\Users\Lomanno\Documents\Arduino\libraries\SPI_LIFA\SPI_LIFA.cpp:12:17: error: SPI.h: No such file or directory
C:\Users\Lomanno\Documents\Arduino\libraries\SPI_LIFA\SPI_LIFA.cpp:14: error: 'SPIClass' does not name a type
C:\Users\Lomanno\Documents\Arduino\libraries\SPI_LIFA\SPI_LIFA.cpp:16: error: 'SPIClass' has not been declared
C:\Users\Lomanno\Documents\Arduino\libraries\SPI_LIFA\SPI_LIFA.cpp: In function 'void begin()':
C:\Users\Lomanno\Documents\Arduino\libraries\SPI_LIFA\SPI_LIFA.cpp:19: error: 'HIGH' was not declared in this scope
C:\Users\Lomanno\Documents\Arduino\libraries\SPI_LIFA\SPI_LIFA.cpp:19: error: 'digitalWrite' was not declared in this scope
C:\Users\Lomanno\Documents\Arduino\libraries\SPI_LIFA\SPI_LIFA.cpp:24: error: 'OUTPUT' was not declared in this scope
C:\Users\Lomanno\Documents\Arduino\libraries\SPI_LIFA\SPI_LIFA.cpp:24: error: 'pinMode' was not declared in this scope
C:\Users\Lomanno\Documents\Arduino\libraries\SPI_LIFA\SPI_LIFA.cpp: At global scope:
C:\Users\Lomanno\Documents\Arduino\libraries\SPI_LIFA\SPI_LIFA.cpp:43: error: 'SPIClass' has not been declared
C:\Users\Lomanno\Documents\Arduino\libraries\SPI_LIFA\SPI_LIFA.cpp:47: error: 'SPIClass' has not been declared
C:\Users\Lomanno\Documents\Arduino\libraries\SPI_LIFA\SPI_LIFA.cpp: In function 'void setBitOrder(uint8_t)':
C:\Users\Lomanno\Documents\Arduino\libraries\SPI_LIFA\SPI_LIFA.cpp:49: error: 'LSBFIRST' was not declared in this scope
C:\Users\Lomanno\Documents\Arduino\libraries\SPI_LIFA\SPI_LIFA.cpp: At global scope:
C:\Users\Lomanno\Documents\Arduino\libraries\SPI_LIFA\SPI_LIFA.cpp:56: error: 'SPIClass' has not been declared
C:\Users\Lomanno\Documents\Arduino\libraries\SPI_LIFA\SPI_LIFA.cpp: In function 'void setDataMode(uint8_t)':
C:\Users\Lomanno\Documents\Arduino\libraries\SPI_LIFA\SPI_LIFA.cpp:58: error: 'SPI_MODE_MASK' was not declared in this scope
C:\Users\Lomanno\Documents\Arduino\libraries\SPI_LIFA\SPI_LIFA.cpp: At global scope:
C:\Users\Lomanno\Documents\Arduino\libraries\SPI_LIFA\SPI_LIFA.cpp:61: error: 'SPIClass' has not been declared
C:\Users\Lomanno\Documents\Arduino\libraries\SPI_LIFA\SPI_LIFA.cpp: In function 'void setClockDivider(uint8_t)':
C:\Users\Lomanno\Documents\Arduino\libraries\SPI_LIFA\SPI_LIFA.cpp:63: error: 'SPI_CLOCK_MASK' was not declared in this scope
C:\Users\Lomanno\Documents\Arduino\libraries\SPI_LIFA\SPI_LIFA.cpp:64: error: 'SPI_2XCLOCK_MASK' was not declared in this scope
my code for SPI_LIFA.h is
/*
* Copyright (c) 2010 by Cristian Maglie <c.maglie@bug.st>
* SPI Master library for arduino.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of either the GNU General Public License version 2
* or the GNU Lesser General Public License version 2.1, both as
* published by the Free Software Foundation.
*/
#ifndef _SPI_LIFA_H_INCLUDED
#define _SPI_LIFA_H_INCLUDED
#include <stdio.h>
#include <Arduino.h>
#include <avr/pgmspace.h>
#define SPI_CLOCK_DIV4 0x00
#define SPI_CLOCK_DIV16 0x01
#define SPI_CLOCK_DIV64 0x02
#define SPI_CLOCK_DIV128 0x03
#define SPI_CLOCK_DIV2 0x04
#define SPI_CLOCK_DIV8 0x05
#define SPI_CLOCK_DIV32 0x06
//#define SPI_CLOCK_DIV64 0x07
#define SPI_MODE0 0x00
#define SPI_MODE1 0x04
#define SPI_MODE2 0x08
#define SPI_MODE3 0x0C
#define SPI_MODE_MASK 0x0C // CPOL = bit 3, CPHA = bit 2 on SPCR
#define SPI_CLOCK_MASK 0x03 // SPR1 = bit 1, SPR0 = bit 0 on SPCR
#define SPI_2XCLOCK_MASK 0x01 // SPI2X = bit 0 on SPSR
class SPIClass {
public:
inline static byte transfer(byte _data);
// SPI Configuration methods
inline static void attachInterrupt();
inline static void detachInterrupt(); // Default
static void begin(); // Default
static void end();
static void setBitOrder(uint8_t);
static void setDataMode(uint8_t);
static void setClockDivider(uint8_t);
};
extern SPIClass SPI;
byte SPIClass::transfer(byte _data) {
SPDR = _data;
while (!(SPSR & _BV(SPIF)))
;
return SPDR;
}
void SPIClass::attachInterrupt() {
SPCR |= _BV(SPIE);
}
void SPIClass::detachInterrupt() {
SPCR &= ~_BV(SPIE);
}
#endif
my code for SPI_LIFA.cpp is
/*
* Copyright (c) 2010 by Cristian Maglie <c.maglie@bug.st>
* SPI Master library for arduino.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of either the GNU General Public License version 2
* or the GNU Lesser General Public License version 2.1, both as
* published by the Free Software Foundation.
*/
#include "pins_arduino.h"
#include "SPI_LIFA.h"
SPIClass SPI;
void SPIClass::begin() {
// Set 3 to high so a connected chip will be "deselected" by default
digitalWrite(3, HIGH);
// When the 3 pin is set as OUTPUT, it can be used as
// a general purpose output port (it doesn't influence
// SPI operations).
pinMode(3, OUTPUT);
// Warning: if the 3 pin ever becomes a LOW INPUT then SPI
// automatically switches to Slave, so the data direction of
// the 3 pin MUST be kept as OUTPUT.
SPCR |= _BV(MSTR);
SPCR |= _BV(SPE);
// Set direction register for SCK and MOSI pin.
// MISO pin automatically overrides to INPUT.
// By doing this AFTER enabling SPI, we avoid accidentally
// clocking in a single bit since the lines go directly
// from "input" to SPI control.
// http://code.google.com/p/arduino/issues/detail?id=888
pinMode(SCK, OUTPUT);
pinMode(MOSI, OUTPUT);
}
void SPIClass::end() {
SPCR &= ~_BV(SPE);
}
void SPIClass::setBitOrder(uint8_t bitOrder)
{
if(bitOrder == LSBFIRST) {
SPCR |= _BV(DORD);
} else {
SPCR &= ~(_BV(DORD));
}
}
void SPIClass::setDataMode(uint8_t mode)
{
SPCR = (SPCR & ~SPI_MODE_MASK) | mode;
}
void SPIClass::setClockDivider(uint8_t rate)
{
SPCR = (SPCR & ~SPI_CLOCK_MASK) | (rate & SPI_CLOCK_MASK);
SPSR = (SPSR & ~SPI_2XCLOCK_MASK) | ((rate >> 2) & SPI_2XCLOCK_MASK);
}