ATTiny24 SPI Slave code error!

Hello all, while compiling the below code for ATTiny24 as SPI slave…i get errors like SPCR, SPDR was not declared in this scope. Why is that happening as the code works fine on an UNO?

#include<SPI.h>
volatile boolean received;
volatile byte Slavereceived, Slavesend;

void setup()

{

  pinMode(5,OUTPUT);                  

  SPCR =SPCR | _BV(SPE);                  
  received = false;

  SPI.attachInterrupt();                  
  
}

ISR (SPI_STC_vect)                        
{
  Slavereceived = SPDR;         
  received = true;                        
}

void loop()
{  
 if(received)                           
 {
  if(Slavereceived==1) 
    digitalWrite(5,HIGH);
  Slavesend = 1;                                  
  SPDR = Slavesend;                       
  delay(1000);
}
}

Sadly, ATtiny24 doesn't have a hardware SPI. :confused:
But it has "USI" is general purpose serial communication hardware.
You need to build SPI slave using the USI.
Please see application note AN2582.
https://www.microchip.com//wwwAppNotes/AppNotes.aspx?appnote=en591657

chrisknightley:
Sadly, ATtiny24 doesn't have a hardware SPI. :confused:
But it has "USI" is general purpose serial communication hardware.
You need to build SPI slave using the USI.
Please see application note AN2582.
https://www.microchip.com//wwwAppNotes/AppNotes.aspx?appnote=en591657

I don't understand anything...I'm new to arduino...is there a library for SPI communication for ATTiny?? If there's not how do i do it?

If you're using ATtinyCore, at least as far as I know I've never seen a library that supports SPI slaves.

ATtinyCore has the SPI library with emulate the standard SPI library using USI.
But, the SPI slave function is not supported, because it doesn't exist in the standard SPI library too.

See the issue below.

You'll probably have to implement the SPI slave yourself.
If you can't do that, change to a microcontroller with hardware SPI.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.