SPI Communication - sending String

Hi guys,
I'm trying to send a string between two micro-controllers via SPI, but I don't have enough programming knowledge.

So far I can send and receive constant value.

My connection:

Master Code (Arduino Leonardo):

#include <SPI.h>

void setup (void) {
 pinMode(8,OUTPUT);
 Serial.begin(9600); //set baud rate to 115200 for usart
 digitalWrite(8, HIGH); // disable Slave Select
 SPI.begin ();
 SPI.setClockDivider(SPI_CLOCK_DIV64);//divide the clock by 8
}

void loop (void) {
 char c;
 digitalWrite(8, LOW); // enable Slave Select

// send test string
 for (const char * p = "Hello, world!\r" ; c = *p; p++) 
 {
 SPI.transfer (c);
 Serial.print(c);
 }
 digitalWrite(8, HIGH); // disable Slave Select
 delay(2000);
}

Slave Code (Arduino UNO):

#include <SPI.h>
char buff [50];
volatile byte indx;
volatile boolean process;

void setup (void) {
 Serial.begin (9600);
 pinMode(12, OUTPUT); // have to send on master in so it set as output
 SPCR |= _BV(SPE); // turn on SPI in slave mode
 indx = 0; // buffer empty
 process = false;
 SPI.attachInterrupt(); // turn on interrupt
}
ISR (SPI_STC_vect) // SPI interrupt routine 
{

byte c= SPDR; // read byte from SPI Data Register
 if (indx < sizeof buff) {
 buff [indx++] = c; // save data in the next index in the array buff
 if (c == '\r') //check for the end of the word
 process = true;
 }
}

void loop (void) {
 
 if (process) {
 
 process = false; //reset the process
 Serial.println (buff); //print the array on serial monitor
 indx= 0; //reset button to zero
 }
 delay(2000);
}

Could you give me a tip how to send a string via SPI? I would like to measure a temperature (DS18B20) on Arduino Leonardo and screen it on LCD which is connected to Arduino UNO.

Regards,
Mateusz

The code that I posted is working. You can see that I’m constantly sending „Hello World”.

My problem is that I do not know how to send STING. I would like to measure a tempreture on my Master and send it to a slave via SPI.

Ok, I will show the code which is NOT working:)
I would like to read value from DS18B20 sensor and send it to SLAVE.

MASTER Code (Arduino Leonardo):

#include <SPI.h>
#include <OneWire.h>
#include <DS18B20.h>

#define ONEWIRE_PIN A0


byte address[8] = {0x28, 0xFF, 0x15, 0xC6, 0x62, 0x15, 0x1, 0x71};

OneWire onewire(ONEWIRE_PIN);

DS18B20 sensors(&onewire);
float temperature=0.0;
String data_to_send="";
void check_temperature()
{
temperature = sensors.readTemperature(address);
        sensors.request(address);
}



void setup (void) 
{
 pinMode(8,OUTPUT);
 Serial.begin(9600); //set baud rate to 115200 for usart
 digitalWrite(8, HIGH); // disable Slave Select
 SPI.begin ();
 SPI.setClockDivider(SPI_CLOCK_DIV64);//divide the clock by 8

  sensors.begin();

  sensors.request(address);
  
 
}

void loop (void) 
{

char c;
digitalWrite(8, LOW); // enable Slave Select
check_temperature();
data_to_send=String(temperatura)+"\r";


 for(char * p = data_to_send[0] ; c = *p; p++) 
 {
 
  Serial.println(c);
  SPI.transfer (c);
  delay(1000);
 }


 //digitalWrite(8, HIGH); // disable Slave Select
 delay(2000);
}

SLAVE Code (Arduino UNO):

#include <SPI.h>
#include <LiquidCrystal.h>


#define pinRS 2
#define pinE 3
#define pinDB4 4
#define pinDB5 5
#define pinDB6 6
#define pinDB7 7

char buff [50];
volatile byte indx;
volatile boolean process;
LiquidCrystal lcd(pinRS, pinE, pinDB4, pinDB5, pinDB6, pinDB7);


void setup (void)
{
 Serial.begin (9600);
 pinMode(12, OUTPUT); // have to send on master in so it set as output
 SPCR |= _BV(SPE); // turn on SPI in slave mode
 indx = 0; // buffer empty
 process = false;
 SPI.attachInterrupt(); // turn on interrupt

   lcd.clear();
  lcd.begin(20, 4);
  lcd.setCursor(0,0);
  lcd.print("Mateusz");
}
ISR (SPI_STC_vect) // SPI interrupt routine 
{

byte c= SPDR; // read byte from SPI Data Register
 if (indx < sizeof buff) {
 buff [indx++] = c; // save data in the next index in the array buff
 if (c == '\r') //check for the end of the word
 process = true;
 }
}

void loop (void) {
 
 if (process) {
 
 process = false; //reset the process
 Serial.println (buff); //print the array on serial monitor
 indx= 0; //reset button to zero
 }
 delay(2000);
}

Arduino UNO is not receiving anything.

 for(char * p = data_to_send[0] ; c = *p; p++)
 {

data_to_send is a String. It is NOT a char array that you can step through one character at a time like this.

There is NO reason to be sending a String OR a string, when what you want to send is a float.

Sending

the

data

one

letter

at

a

time

with

a

long

delay

is

silly.