user49095: I use a mega as a master and a nano as a slave.
Both should convey texts. However, I get the master always only the answer that I send.
The text from the slave does not arrive.
Master:
#include <SPI.h>
volatile boolean senden;
volatile char Paket_vom_Slave;
volatile char Paket_zum_Slave;
char buf [100];
volatile byte pos;
String Paket = "";
char x;


void setup (void)

{
  Serial.begin(9600);
  pinMode(53, OUTPUT);
  pinMode(SS, OUTPUT);
  digitalWrite(SS, HIGH);  //SS Pin auf HIGH setzten
  SPI.begin ();  //Verbindung starten
  SPI.setClockDivider(SPI_CLOCK_DIV8);  //Geschwindigkeit verlangsamen
}

void loop (void)
{
  //Text_erstellen();

  digitalWrite(SS, LOW);    //starten der Kommunikation mit Slave

  for (const char * p = "TxT v Master\n" ; Paket_zum_Slave = *p; p++)
  {
    //Text_erstellen();
    Paket_vom_Slave = SPI.transfer(Paket_zum_Slave); //senden von Text
    Text_erstellen();
    delayMicroseconds (500);
    Serial.print("sent: ");
    Serial.print(Paket_zum_Slave);
    Serial.print("\t empfangen: ");
    //Serial.println(Paket_vom_Slave);
    Serial.println(Paket);
    delay(200);
  }
  digitalWrite(SS, HIGH);  //beenden der Kommunikation
  delay (1000);  //kurze pause

}

void Text_erstellen()
{
  char c = Paket_vom_Slave;  //kopieren der Daten von SPI Buffer
  if (pos < sizeof buf)
  {
    buf [pos++] = c;  //hinzufuegen des naechsten Zeichens
    if (c == '\n')
      senden = true;
  }
  if (senden)
  {
    buf[pos] = 0;
    Paket = (buf);
    x = buf;
    Paket.trim();
    Serial.println (("empfangen :--->") + (Paket));
    Serial.println (("empfangen :--->") + (Paket));
    Serial.println (("empfangen :--->") + (Paket));
    pos = 0;
    senden = false;

  }
}

Slave:
#include <SPI.h>
volatile boolean senden;
volatile boolean versandbereit;
//volatile byte Paket_Master,Sendung_Slave;
volatile char Paket_Master;
volatile char Sendung_Slave;
String Paket = "";
String Sendung = "";
int i = -1;
char buf[20];
char buf1[20];
volatile byte pos;
volatile byte pos1;


void setup(void)
{
  Serial.begin(9600);


 pinMode(12, OUTPUT);
  pinMode(MISO, OUTPUT);
 SPCR |= _BV(SPE);         // turn on SPI in slave mode


  //SPCR |= bit (SPE);
  senden = false;
  SPCR |= _BV(SPIE);   // turn on interrupts
  SPI.attachInterrupt();
}

void loop(void)
{

  if ((versandbereit) == false);
  {
    Paket_Text();
  }

  if (senden)
  {
    i = i + 1;

    buf[pos] = 0;
    Paket = (buf);
    buf1[pos] = 0;
    Sendung = (buf1);

    if (i == 12)
    {
      SPDR = "\n";
    }
    else
    {
      SPDR = (buf1[i]);
    }
    Paket.trim();
    Sendung.trim();
    Serial.println (("empfangen :--->") + (Paket));
    Serial.println (buf1[i]);
    Serial.println (i);
    Serial.println (("gesendet  :--->") + (Sendung));

    pos = 0;
    senden = false;
  }

  if (i == 12) i = -1;
}

ISR(SPI_STC_vect)
{

  byte c = SPDR;  //kopieren der Daten von SPI Buffer
  if (pos < sizeof buf)
  {
    buf[pos++] = c;  //hinzufuegen des naechsten Zeichens
    if (c == '\n')
      senden = true;
  }
}

void Paket_Text()
{
  if (pos1 < sizeof buf1)
    for (const char * p = "Paket--Slave\n" ; char c = *p; p++)
    {
      buf1[pos1++] = c;
                            Serial.println (buf1);
      if (c == '\n')
        versandbereit = true;
    }
}

I've updated the code above.
The slave now sends bitwise the same text length as it should, but another text like the master sent.
Unfortunately, the master always receives what he sends, not what comes from the slave.

I'm getting on slowly :-)
But I currently have a problem with the data transfer.
I hand over at startup: char package_to_master [50] = "Start from the slave.";
and change SPI interrupt routine content with "new text"
but is sent "starting from the slave."
How should I change that?
// Slave
char Paket_zum_Master[50] = "Starten vom Slave.";
volatile int pos;
volatile bool active;
String Send_Paket;
ISR (SPI_STC_vect)    // SPI interrupt routine
{
  Send_Paket = "neuer Text";
  char Sendung = ((Send_Paket + "\n").c_str());
  Paket_zum_Master[50] = Sendung;
  byte c = SPDR;
  if (c == 1)  // starting new sequence?
  {
    active = true;
    pos = 0;
    SPDR = Paket_zum_Master[pos++];   // sendet erste byte
    return;
  }
  if (!active)
  {
    SPDR = 0;
    return;
  }
  SPDR = Paket_zum_Master[pos];
  if (Paket_zum_Master[pos] == 0 || ++pos >= sizeof(Paket_zum_Master))
    //wenn pos=0 oder größer 1
    active = false;
}  // end


user37622: You do not have pinMode(SS, OUTPUT); in setup() of the master.

49095: <p>I use a mega as a master and a nano as a slave.<br>
Both should convey texts. However, I get the master always only the answer that I send.<br>
The text from the slave does not arrive.</p>

<p>Master:</p>

<pre class="lang-c++ prettyprint-override"><code>#include &lt;SPI.h&gt;
volatile boolean senden;
volatile char Paket_vom_Slave;
volatile char Paket_zum_Slave;
char buf [100];
volatile byte pos;
String Paket = "";
char x;


void setup (void)

{
  Serial.begin(9600);
  pinMode(53, OUTPUT);
  pinMode(SS, OUTPUT);
  digitalWrite(SS, HIGH);  //SS Pin auf HIGH setzten
  SPI.begin ();  //Verbindung starten
  SPI.setClockDivider(SPI_CLOCK_DIV8);  //Geschwindigkeit verlangsamen
}

void loop (void)
{
  //Text_erstellen();

  digitalWrite(SS, LOW);    //starten der Kommunikation mit Slave

  for (const char * p = "TxT v Master\n" ; Paket_zum_Slave = *p; p++)
  {
    //Text_erstellen();
    Paket_vom_Slave = SPI.transfer(Paket_zum_Slave); //senden von Text
    Text_erstellen();
    delayMicroseconds (500);
    Serial.print("sent: ");
    Serial.print(Paket_zum_Slave);
    Serial.print("\t empfangen: ");
    //Serial.println(Paket_vom_Slave);
    Serial.println(Paket);
    delay(200);
  }
  digitalWrite(SS, HIGH);  //beenden der Kommunikation
  delay (1000);  //kurze pause

}

void Text_erstellen()
{
  char c = Paket_vom_Slave;  //kopieren der Daten von SPI Buffer
  if (pos &lt; sizeof buf)
  {
    buf [pos++] = c;  //hinzufuegen des naechsten Zeichens
    if (c == '\n')
      senden = true;
  }
  if (senden)
  {
    buf[pos] = 0;
    Paket = (buf);
    x = buf;
    Paket.trim();
    Serial.println (("empfangen :---&gt;") + (Paket));
    Serial.println (("empfangen :---&gt;") + (Paket));
    Serial.println (("empfangen :---&gt;") + (Paket));
    pos = 0;
    senden = false;

  }
}
</code></pre>

<p>Slave:</p>

<pre class="lang-c++ prettyprint-override"><code>#include &lt;SPI.h&gt;
volatile boolean senden;
volatile boolean versandbereit;
//volatile byte Paket_Master,Sendung_Slave;
volatile char Paket_Master;
volatile char Sendung_Slave;
String Paket = "";
String Sendung = "";
int i = -1;
char buf[20];
char buf1[20];
volatile byte pos;
volatile byte pos1;


void setup(void)
{
  Serial.begin(9600);


 pinMode(12, OUTPUT);
  pinMode(MISO, OUTPUT);
 SPCR |= _BV(SPE);         // turn on SPI in slave mode


  //SPCR |= bit (SPE);
  senden = false;
  SPCR |= _BV(SPIE);   // turn on interrupts
  SPI.attachInterrupt();
}

void loop(void)
{

  if ((versandbereit) == false);
  {
    Paket_Text();
  }

  if (senden)
  {
    i = i + 1;

    buf[pos] = 0;
    Paket = (buf);
    buf1[pos] = 0;
    Sendung = (buf1);

    if (i == 12)
    {
      SPDR = "\n";
    }
    else
    {
      SPDR = (buf1[i]);
    }
    Paket.trim();
    Sendung.trim();
    Serial.println (("empfangen :---&gt;") + (Paket));
    Serial.println (buf1[i]);
    Serial.println (i);
    Serial.println (("gesendet  :---&gt;") + (Sendung));

    pos = 0;
    senden = false;
  }

  if (i == 12) i = -1;
}

ISR(SPI_STC_vect)
{

  byte c = SPDR;  //kopieren der Daten von SPI Buffer
  if (pos &lt; sizeof buf)
  {
    buf[pos++] = c;  //hinzufuegen des naechsten Zeichens
    if (c == '\n')
      senden = true;
  }
}

void Paket_Text()
{
  if (pos1 &lt; sizeof buf1)
    for (const char * p = "Paket--Slave\n" ; char c = *p; p++)
    {
      buf1[pos1++] = c;
                            Serial.println (buf1);
      if (c == '\n')
        versandbereit = true;
    }
}
</code></pre>

<p>I've updated the code above.<br>
The slave now sends bitwise the same text length as it should, but another text like the master sent.<br>
Unfortunately, the master always receives what he sends, not what comes from the slave.</p>

<hr>

<p>I'm getting on slowly :-)</p>

<p>But I currently have a problem with the data transfer.
I hand over at startup: char package_to_master [50] = "Start from the slave.";
and change SPI interrupt routine content with "new text"
but is sent "starting from the slave."
How should I change that?</p>

<pre class="lang-c++ prettyprint-override"><code>// Slave
char Paket_zum_Master[50] = "Starten vom Slave.";
volatile int pos;
volatile bool active;
String Send_Paket;
ISR (SPI_STC_vect)    // SPI interrupt routine
{
  Send_Paket = "neuer Text";
  char Sendung = ((Send_Paket + "\n").c_str());
  Paket_zum_Master[50] = Sendung;
  byte c = SPDR;
  if (c == 1)  // starting new sequence?
  {
    active = true;
    pos = 0;
    SPDR = Paket_zum_Master[pos++];   // sendet erste byte
    return;
  }
  if (!active)
  {
    SPDR = 0;
    return;
  }
  SPDR = Paket_zum_Master[pos];
  if (Paket_zum_Master[pos] == 0 || ++pos &gt;= sizeof(Paket_zum_Master))
    //wenn pos=0 oder größer 1
    active = false;
}  // end
</code></pre>
 37622: <p>You do not have <code>pinMode(SS, OUTPUT);</code> in <code>setup()</code> of the master.</p>
