I have programmed Attiny88 with Arduino IDE 1.6.5 using https://github.com/SpenceKonde/ATTinyCore . I chose Attiny88 because it's the cheapest Attiny (as low as $0.5) and at the same time has 28 pins with dedicated SPI. I wrote a code for arduino to work as SPI master, and a code for Attiny88 as SPI slave but I get only 0 as answer from Attiny.
SPI master code for ARduino UNO
#include <SPI.h>
// set up the speed, data order and data mode
SPISettings settingsA(2000000, MSBFIRST, SPI_MODE0);
const int slaveAPin = 10;
void setup() {
// set the Slave Select Pins as outputs:
Serial.begin(9600);
Serial.println("SPI ON");
pinMode (slaveAPin, OUTPUT);
SPI.begin();
}
uint8_t stat, val1, result;
void loop() {
// read two bytes from device A
SPI.beginTransaction(settingsA);
digitalWrite (slaveAPin, LOW);
// reading only, so data sent does not matter
stat = SPI.transfer(0);
val1 = SPI.transfer(0);
digitalWrite (slaveAPin, HIGH);
SPI.endTransaction();
Serial.println("data");
Serial.println(stat);
Serial.println(val1);
Serial.println("end");
SPI.endTransaction();
delay(300);
}
SPI slave code for Attiny88:
#include <SPI.h>
// set up the speed, data order and data mode
SPISettings settingsA(2000000, MSBFIRST, SPI_MODE0);
const int slavePin = 14;
const int ledPin = 9;
uint8_t stat, val1, val2, result;
void setup() {
// set the Slave Select Pins as outputs:
pinMode (slavePin, INPUT);
pinMode (ledPin, OUTPUT);
// initialize SPI:
digitalWrite(ledPin, HIGH);
delay(1000);
SPI.begin();
stat =128;
val1= 1;
}
void loop() {
if (slavePin==LOW) {
SPI.beginTransaction(settingsA);
SPI.transfer(stat);
SPI.transfer(val1);
result = SPI.transfer(0);
digitalWrite(ledPin, result);
SPI.endTransaction();
}
}