Last active
October 1, 2023 14:00
-
-
Save SimedruF/1fe3f8be4b8be83130eb0eef1e285059 to your computer and use it in GitHub Desktop.
SPI master
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Florin Simedru | |
Complete project details at https://blog.automatic-house.ro | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files. | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
*/ | |
/* | |
PlatformIO Project Configuration File; | |
; | |
Build options : build flags, source filter; | |
Upload options : custom upload port, speed and extra flags; | |
Library options : dependencies, extra library storages; | |
Advanced options : extra scripting; | |
; Please visit documentation for the other options and examples | |
; | |
https : // docs.platformio.org/page/projectconf.html | |
[env:uno] | |
platform = atmelavr | |
board = uno | |
framework = arduino | |
upload_port = COM8 | |
monitor_port = COM8 | |
monitor_speed = 115200 | |
*/ | |
#include <Arduino.h> | |
#include <SPI.h> | |
byte transferAndWait(const byte what); | |
void setup(void) | |
{ | |
Serial.begin(115200); | |
Serial.println(); | |
digitalWrite(SS, HIGH); // ensure SS stays high for now | |
SPI.begin(); | |
// Slow down the master a bit | |
SPI.setClockDivider(SPI_CLOCK_DIV8); | |
} // end of setup | |
byte transferAndWait(const byte what) | |
{ | |
byte a = SPI.transfer(what); | |
delayMicroseconds(80); | |
return a; | |
} // end of transferAndWait | |
void loop(void) | |
{ | |
byte a, b; | |
// enable Slave Select | |
digitalWrite(SS, LOW); | |
transferAndWait(0); | |
b = transferAndWait(0); | |
a = transferAndWait(0); | |
// disable Slave Select | |
digitalWrite(SS, HIGH); | |
Serial.println(a, DEC); | |
delay(200); // 0.100 second delay | |
} // end of loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment