#include <SPI.h>
#define CS 10
void setup() {
char buffer[] = "Hello hamada"; // The data to send
int bufferLength = strlen(buffer); // Calculate the length of the buffer
Serial.begin(9600);
pinMode(CS, OUTPUT);
digitalWrite(CS, HIGH);
// Begin SPI communication
SPI.begin();
// Select the SPI device by pulling the CS pin LOW
digitalWrite(CS, LOW);
// Transfer the entire buffer at once using SPI.transfer function in a loop
for (int i = 0; i <= bufferLength; i++) {
buffer[i] = SPI.transfer(buffer[i]);
}
// Deselect the SPI device by pulling the CS pin HIGH
digitalWrite(CS, HIGH);
// End SPI communication
SPI.end();
// Print the received data
Serial.println("Data received from SPI device:");
Serial.println(buffer);
}
void loop() {
// Nothing to do here
}