Here is where i got with an idea to pass array, didn't work....
Master code
//Master
#include <SPI.h>
int slaveSelect[] = {36, 38, 40};
int SS_one = 36; //slave select on pin 36
int SS_two = 38;
int SS_three = 40;
void setup (void)
{
Serial.begin (115200);
Serial.println ();
pinMode(SS_one, OUTPUT); //assigning slave select one
digitalWrite(SS_one, HIGH);
pinMode(SS_two, OUTPUT); //assigning slave select two
digitalWrite(SS_two, HIGH);
pinMode(SS_three, OUTPUT); //assigning slave select three
digitalWrite(SS_three, HIGH);
digitalWrite(SS, HIGH); // ensure SS stays high for now
// Put SCK, MOSI, SS pins into output mode
// also put SCK, MOSI into LOW state, and SS into HIGH state.
// Then put SPI hardware into Master mode and turn SPI on
SPI.begin ();
// Slow down the master a bit
SPI.setClockDivider(SPI_CLOCK_DIV8);
} // end of setup
byte getSlaveInfo(int slavePin) {
digitalWrite(slavePin, LOW);
int data[8] = {'a'};
// for (int i = 0; i < sizeof data; i++) {
SPI.transfer(*data, (sizeof data));
// }
Serial.print('[');
Serial.print(data[0]);
Serial.print(']');
SPI.transfer(0);
digitalWrite(slavePin, HIGH);
return data;
}
void loop (void)
{
int a_total;
int a1, a2, a3;
/*
byte b;
byte bb;
byte bbb;
*/
//adding stuff, command a
// enable Slave Select
digitalWrite(SS_one, LOW); //enabling slave, to read data
// int slaveOneData[] = getSlaveInfo(SS_one);
Serial.print("Slave Status:1:");
Serial.println(getSlaveInfo(SS_one));
/*
long slaveTwoData = getSlaveInfo(SS_two);
Serial.print("Slave Status:2:");
Serial.println(slaveTwoData);
long slaveThreeData = getSlaveInfo(SS_three);
Serial.print("Slave Status:3:");
Serial.println(slaveThreeData);
*/
delay(1000);
Serial.println('\n');
Slave
//Slave
#include <SPI.h>
#include "Wire.h" //wire class, for serial communication
//Global Variables, to be changed by programer
int SLAVE_ID = 2; //Slave Is, change this while programming the boards, to corrispond to their address in the verifier
volatile byte command = 0;
//int ABSOLUTE_VALUE =0;
int MULTI = 0;
int REMINDER = 0;
void setup (void)
{
// have to send on master in, *slave out*
pinMode(MISO, OUTPUT);
// turn on SPI in slave mode
SPCR |= _BV(SPE);
// turn on interrupts
SPCR |= _BV(SPIE);
Serial.begin(9600);
} // end of setup
// SPI interrupt routine
ISR (SPI_STC_vect)
{
uint64_t c = SPDR;
//data.select = SPDR;
int d[] = {1, 0, 1, 0, 1, 1, 0, 0};
// for (int i = 0; i < sizeof d; i++) {
SPI.transfer(d, (sizeof d));
// }
/*
switch (command)
{
// no command? then this is the command
case 0:
command = c;
SPDR = 0;
break;
// add to incoming byte, return result
case 'a':
SPDR = 255;
break;
case 'b':
SPDR = 45;
break;
case 'c':
SPDR = 0;
break;
case 'd':
SPDR = 0;
break;
case 'e':
SPDR = 0;
break;
case 'f':
SPDR = 0;
break;
case 'g':
SPDR = 0;
break;
case 'h':
SPDR = 0;
break;
// subtract from incoming byte, return result
case 's':
SPDR = c - 8; // subtract 8
break;
} // end of switch
*/
} // end of interrupt service routine (ISR) SPI_STC_vect
void loop (void)
{
// if SPI not active, clear current command
if (digitalRead (SS) == HIGH)
{
command = 0;
Serial.print ("no longer reading");
}
Serial.println(check_pins(0), DEC);
/*
while(MULTI <= 0)
{
Serial.print("part is: ");
Serial.println(check_pins_2(0));
MULTI = MULTI-1;
}
*/
/*
if(MULTI >=0)
{
MULTI = MULTI-1;
Serial.println("250");
}
else
{
Serial.println(REMINDER);
}
*/
} // end of loop
int check_pins (int whatever)
{
int ABSOLUTE_VALUE = 300;
/*
for(int pinNum = 22; pinNum <= 49; pinNum++) //this while looper will cycle through the lower and upper pins, scanning and reporting the state of each pin, printing across the serial communication port.
{
int myPin = pinNum;
pinMode(myPin, INPUT);
if (digitalRead(myPin) == true) //if the pin is high
{
ABSOLUTE_VALUE += ( myPin); //add to absolute_value
}
//ABSOLUTE_VALUE += (SLAVE_ID*160) + 1;
}
*/
if (ABSOLUTE_VALUE <=250)
{
if (ABSOLUTE_VALUE == 250)
{
MULTI = 1;
}
else
{
MULTI = 0;
}
}
else
{
MULTI = (int)ABSOLUTE_VALUE / 250;
}
//MULTI = (int)ABSOLUTE_VALUE / 250;
REMINDER = ABSOLUTE_VALUE % 250; /* Likely uses the result of the division. */
return ABSOLUTE_VALUE;
}
int check_pins_2( int whatever)
{
int substract = whatever;
int ABSOLUTE_VALUE = check_pins (0);
if (ABSOLUTE_VALUE <= 250)
{
return ABSOLUTE_VALUE;
}
else
{
if(MULTI >=0)
{
MULTI = MULTI-substract;
return 250;
}
else
{
return REMINDER;
}
}
}