I tried the whole process by using two arduino unos.It worked perfectly. Though when i tried to replace the slave uno with attiny 84 uC it showed following errors in compiling.

Arduino: 1.6.7 (Windows 7), Board: "ATtiny24/44/84, ATtiny84 @ 1 MHz  (internal oscillator; BOD disabled)"

WARNING: Category '' in library ArduinoJson is not valid. Setting to 'Uncategorized'
C:\Users\LEGEND\AppData\Local\Temp\arduino_8a75bcb6a2713182a57eb1014198ceb3\sketch_may12c.ino: In function 'void setup()':

sketch_may12c:12: error: 'SPCR' was not declared in this scope

   SPCR |= bit (SPE);


In file included from C:\Users\LEGEND\AppData\Local\Arduino15\packages\tiny\hardware\avr\1.0.0\cores\tiny/WProgram.h:12:0,

                 from C:\Users\LEGEND\AppData\Local\Arduino15\packages\tiny\hardware\avr\1.0.0\cores\tiny/Arduino.h:4,

                 from sketch\sketch_may12c.ino.cpp:1:

sketch_may12c:12: error: 'SPE' was not declared in this scope

   SPCR |= bit (SPE);


C:\Users\LEGEND\AppData\Local\Arduino15\packages\tiny\hardware\avr\1.0.0\cores\tiny/wiring.h:158:25: note: in definition of macro 'bit'

 #define bit(b) (1UL << (b))


sketch_may12c:15: error: 'MISO' was not declared in this scope

   pinMode (MISO, OUTPUT);


sketch_may12c:22: error: expected unqualified-id before '.' token



C:\Users\LEGEND\AppData\Local\Temp\arduino_8a75bcb6a2713182a57eb1014198ceb3\sketch_may12c.ino: In function 'void SPI_STC_vect()':

sketch_may12c:30: error: 'SPDR' was not declared in this scope

 byte c = SPDR;  // grab byte from SPI Data Register


exit status 1
'SPCR' was not declared in this scope

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.
  • Sounds like a bug in the core. – Ignacio Vazquez-Abrams May 12 '16 at 13:09
  • It has to do with SPI. – Gerben May 12 '16 at 15:15
  • Could you post the content of sketch_may2c.ino as it seems this is where the erroneous code is. – jfpoilpret May 12 '16 at 19:27
  • #include <SPI.h> char buf [100]; volatile byte pos; volatile bool 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; – Rishabh Dutta May 16 '16 at 6:16
  • continued..................... // 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) { buf [pos++] = c; // example: newline means time to process buffer if (c == '\n') process_it = true; } // end of room available } // end of interrupt routine SPI_STC_vect – Rishabh Dutta May 16 '16 at 6:17

You are trying to compile the wrong program for the wrong chip.

The nice thing about the Arduino core library is that it enables you to write code that is portable across various Arduino boards. However, this library provides very limited access to the capabilities of the underlying hardware. Then, it is quite common for users to mix Arduino code with C statements that directly access the hardware registers. Doing this provides full control over the hardware, at the cost of reduced portability.

Just an example from your code:

SPCR |= bit (SPE);

This line is accessing the control register of the SPI port (SPCR means “SPI Control Register”) in order to set to 1 the bit named SPE (for “SPI Enable”). This is the “bare metal” way of turning on the SPI port.

Now, your problem is that, unlike the ATmega328P powering your Unos, the ATtiny84 does not have a hardware SPI port. Thus the line above just makes no sense.

The solution: you have to figure out some other means for your chip to talk SPI. You could emulate it purely in software, but it would certainly be more efficient to use the USI port. The USI (“Universal Serial Interface”) is a multipurpose serial port found in many ATtinies. It can be configured to do SPI, I2C or simplex/half-duplex UART.

Recommended readings:

You may be able to find ready-made libraries for doing this.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.