Hi all!
I'm receiving this error message and I've looked into a bit, and I'm not sure why I am receiving the message.
The code I am trying to use is Nick Gammon's SPI examples found Here
Here's the specific code I am using:
// http://www.gammon.com.au/spi
// Written by Nick Gammon
// February 2011
#include <SPI.h>
char buf [100];
volatile byte pos;
volatile boolean process_it;
void setup (void)
{
Serial.begin (115200); // debugging
// turn on SPI in slave mode
SPCR |= bit (SPE);
// have to send on master in, *slave out*
pinMode(MISO, OUTPUT);
// get ready for an interrupt
pos = 0; // buffer empty
process_it = false;
// now turn on interrupts
SPI.attachInterrupt();
} // end of setup
// SPI interrupt routine
ISR (SPI_STC_vect)
{
byte c = SPDR; // grab byte from SPI Data Register
// add to buffer if room
if (pos < (sizeof (buf) - 1))
buf [pos++] = c;
// example: newline means time to process buffer
if (c == '\n')
process_it = true;
} // end of interrupt routine SPI_STC_vect
// main loop - wait for flag set in interrupt routine
void loop (void)
{
if (process_it)
{
buf [pos] = 0;
Serial.println (buf);
pos = 0;
process_it = false;
} // end of flag set
} // end of loop
I'm using arduino IDE 1.8.5 and the code compiles just fine for an Arduino Uno. The problems comes when I switch to an Arduino Zero (native port) board in the IDE. When I switch to that board, the error message is:
SPI_test_Slave:33: error: expected constructor, destructor, or type conversion before '(' token
ISR (SPI_STC_vect)
^
C:\Documents and Settings\User\My Documents\Arduino\SPI_test_Slave\SPI_test_Slave.ino: In function 'void setup()':
SPI_test_Slave:17: error: 'SPCR' was not declared in this scope
SPCR |= bit (SPE);
^~~~
C:\Documents and Settings\User\My Documents\Arduino\SPI_test_Slave\SPI_test_Slave.ino:17:3: note: suggested alternative: 'SPI'
SPCR |= bit (SPE);
^~~~
SPI
In file included from sketch\SPI_test_Slave.ino.cpp:1:0:
SPI_test_Slave:17: error: 'SPE' was not declared in this scope
SPCR |= bit (SPE);
^
C:\Documents and Settings\User\Local Settings\Application Data\Arduino15\packages\arduino\hardware\samd\1.8.6\cores\arduino/Arduino.h:120:25: note: in definition of macro 'bit'
#define bit(b) (1UL << (b))
^
C:\Documents and Settings\User\My Documents\Arduino\SPI_test_Slave\SPI_test_Slave.ino:17:16: note: suggested alternative: 'SPI'
SPCR |= bit (SPE);
^
C:\Documents and Settings\User\Local Settings\Application Data\Arduino15\packages\arduino\hardware\samd\1.8.6\cores\arduino/Arduino.h:120:25: note: in definition of macro 'bit'
#define bit(b) (1UL << (b))
^
C:\Documents and Settings\User\My Documents\Arduino\SPI_test_Slave\SPI_test_Slave.ino: At global scope:
SPI_test_Slave:33: error: expected constructor, destructor, or type conversion before '(' token
ISR (SPI_STC_vect)
^
exit status 1
expected constructor, destructor, or type conversion before '(' token
I've looked into this error message, but it appears to not be from the usual causes, plus there's the fact that it compiles fine for an Uno, but not a Zero that has me stumped at the moment.
Any insight would be most welcomed!
Randy