Hi,
I have done my project using
it helped me a lot.
now i have to connect two arduinos as slaves
can you help me with this?
Thank you.
#include <SPI.h>
const int SS = 10;
onst int SS1 = 8;
const int SS2 = 9;
byte slave = 0;
void setup (void)
{
digitalWrite(SS1,LOW);
digitalWrite(SS2,HIGH);
pinMode(10, OUTPUT);
// ensure SS stays high for now
pinMode (SS1, OUTPUT);
pinMode (SS2, OUTPUT);
// 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
void loop (void)
{
char c;
switch (slave) {
case 0:
digitalWrite(SS2,HIGH);
for (const char * p = "Hello, world!\n" ; c = *p; p++)
SPI.transfer (c);
delay(1000);
digitalWrite(SS1,LOW);
break;
case 1:
digitalWrite(SS1,HIGH);
for (const char * p = "Hello, world!\n" ; c = *p; p++)
SPI.transfer (c);
delay(1000);
digitalWrite(SS2,LOW);
break;
} // end of loop
I am connecting arduinos to pins 8 and 9.
is this code correct?
Thank you.