Help with SPI on ATtiny44 slave and Micro master

Hi, I have had a helluva time getting a slave code to work on the tiny44/84. I finally have something that uploads, but it doesn’t seem to do anything…

The tinySPI library gives me all kinds of compiler errors, and I think there’s a compatibility issue with arduino1.6.7. I can post those if it would be useful, but in the meantime, I’ve tried to adapt some code from here, (thanks Abek42), for the slave, and use the SPI library for the master. I’m not sure if the SPI settings are right, if I’m using the right commands to send and receive data, etc.

Heres the code…


#include <SPI.h>

const int slaveAPin = 7;

SPISettings settingsA(16000000, MSBFIRST, SPI_MODE3);

void setup() {
  pinMode (slaveAPin, OUTPUT);


byte stat, val1, val2, result;

void loop() {
  stat = 10101010;
  digitalWrite (slaveAPin, LOW);

  result = SPI.transfer(0);

  digitalWrite (slaveAPin, HIGH);



  SPI Slave Test Program on ATTiny84
  Abe Karnik 27-Jun-2013

//chip pin to internal digital assignment
#define PPP7   4 //MOSI
#define PPP8   5 //MISO
#define PPP9   6 //USCK 
#define PPP12  10 //PCINT1 CS (Chip select interrupt)

//SPI Defines
#define MOSI PPP7
#define MISO PPP8
#define SCK  PPP9
#define CS   PPP12

#define CMDNONE 0
#define CMDRECV 1 //receive data from master
#define CMDSEND 2 //send data to master

bool csLow = false;
byte cmdtype = CMDNONE; //no command to start with.
byte byteout = 0; //
byte pinmask = 55;

// the setup routine runs once when you press reset:
void setup() {
  // initialize the digital pin as an output.

// the loop routine runs over and over again forever:
void loop() {


void setupSPI() {
  //pin setup
  pinMode(MOSI,   INPUT);
  pinMode(MISO,  OUTPUT);
  pinMode(SCK,    INPUT);
  pinMode(CS,     INPUT);
  //chip select interrupt
  attachInterrupt(CS, chipSelect, FALLING);
  //actual USI setup
  USICR = 0; //set everything to zero.
  USICR = (1 << USIWM0) | (1 << USICS1) | (1 << USIOIE); //Three wire mode0, External clock positive edge both edges, Enable interrupt

//first Mega will select the chip
void chipSelect() {                                           //this tells the Tiny that the data coming in is for it.
  csLow = true;                                               //resetting is the job of the SPI overflow handler

//then send the message which should trigger the ISR
{ //overflow
  byte c = USIDR;                                             //read the USI Data Buffer
  USISR = 1 << USIOIF;                                        //clear the interrupt flag, yeah I know, it needs to be set to 1 to clear and reset the counter
  if (csLow) {                                                //this slave is selected, so command is for this slave
    byteout = c;                                              //save the command
    PORTA = byteout;
    byte bytereturn = (byteout - pinmask);
    pinMode(MISO, OUTPUT);                                    //only when sending out a byte
    USIDR = bytereturn;
    pinMode(MISO, INPUT);                                     //reverse it so it doesn't interfere with other slaves
       PORTA = 0;
}  // end of interrupt service routine (ISR) SPI_STC_vect

thanks for any help!