Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save iotguider/e3225f6ad68fb99b254d1bcd93c10d8b to your computer and use it in GitHub Desktop.
Save iotguider/e3225f6ad68fb99b254d1bcd93c10d8b to your computer and use it in GitHub Desktop.
Code for Master Arduino for SPI Communication
#include <SPI.h>
void setup() {
Serial.begin(115200); //set baud rate to 115200 for usart
digitalWrite(SS, HIGH); // disable Slave Select
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV8);//divide the clock by 8
}
void loop() {
char c;
digitalWrite(SS, LOW); // enable Slave Select
// send test string
for (const char * p = "Hello, world!\r" ; c = *p; p++) {
SPI.transfer (c);
Serial.print(c);
}
digitalWrite(SS, HIGH); // disable Slave Select
delay(2000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment