From 220cad85f1a8c43ffd7b91c51cae661c342c0bb0 Mon Sep 17 00:00:00 2001 From: Nathan Seidle Date: Sat, 25 Jan 2020 14:54:16 -0700 Subject: [PATCH 1/2] Add example configuring alternate SPI ports. --- .../examples/Example1_SPI/Example1_SPI.ino | 2 +- .../Example2_MoreSPIPorts.ino | 54 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 libraries/SPI/examples/Example2_MoreSPIPorts/Example2_MoreSPIPorts.ino diff --git a/libraries/SPI/examples/Example1_SPI/Example1_SPI.ino b/libraries/SPI/examples/Example1_SPI/Example1_SPI.ino index 3f87d3f..4dd5853 100644 --- a/libraries/SPI/examples/Example1_SPI/Example1_SPI.ino +++ b/libraries/SPI/examples/Example1_SPI/Example1_SPI.ino @@ -20,7 +20,7 @@ const char *msg = "Hello world!"; void setup() { - Serial.begin(9600); + Serial.begin(115200); while (!Serial) { }; //Wait for user to open terminal window diff --git a/libraries/SPI/examples/Example2_MoreSPIPorts/Example2_MoreSPIPorts.ino b/libraries/SPI/examples/Example2_MoreSPIPorts/Example2_MoreSPIPorts.ino new file mode 100644 index 0000000..5bc05c0 --- /dev/null +++ b/libraries/SPI/examples/Example2_MoreSPIPorts/Example2_MoreSPIPorts.ino @@ -0,0 +1,54 @@ +/* Author: Owen Lyke + Created: May 13 2019 + License: MIT. See SparkFun Arduino Apollo3 Project for more information + + This example demonstrates how to use Arduino SPI +*/ + +#include "SPI.h" + +#define CS_PIN 2 + +#define SPI_SPEED 1000000 +#define SPI_ORDER MSBFIRST +#define SPI_MODE SPI_MODE0 + +SPISettings mySettings(SPI_SPEED, SPI_ORDER, SPI_MODE); + +const char *msg = "Hello world!"; + +//SPIClass SPI(); //This is default and automatically defined on RedBoard/ATP/Nano. Uses pads 5/6/7 (SCK/MISO/MOSI). +SPIClass SPI1(1); //Use IO Master 1 on pads 8/9/10 +// SPIClass mySPI(2); //Use IO Master 2 on pads 27/25/28 +// SPIClass anotherSPI(3); //Use IO Master 3 on pads 42/43/44 +// SPIClass SPI4(4); //Use IO Master 4 on pads 39/40/38 +// SPIClass SPI5(5); //Use IO Master 5 on pads 48/49/47 + +void setup() +{ + Serial.begin(115200); + while (!Serial) + { + }; //Wait for user to open terminal window + + Serial.println("SparkFun Arduino Apollo3 SPI Example"); + Serial.printf("Compiled on %s, %s\n\n", __DATE__, __TIME__); + + SPI1.begin(); + + pinMode(CS_PIN, OUTPUT); +} + +void loop() +{ + digitalWrite(CS_PIN, LOW); + SPI1.beginTransaction(mySettings); + SPI1.transfer(0xAA); + SPI1.endTransaction(); + + SPI1.beginTransaction(mySettings); + SPI1.transferOut((void *)msg, strlen(msg)); + SPI1.endTransaction(); + digitalWrite(CS_PIN, HIGH); + delay(1000); +} \ No newline at end of file From bc0c12eafde1edb43007f34b7d53c1fe9abf96f8 Mon Sep 17 00:00:00 2001 From: Nathan Seidle Date: Thu, 6 Feb 2020 12:27:07 -0700 Subject: [PATCH 2/2] Add a few comments. --- .../examples/Example2_MoreSPIPorts/Example2_MoreSPIPorts.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/SPI/examples/Example2_MoreSPIPorts/Example2_MoreSPIPorts.ino b/libraries/SPI/examples/Example2_MoreSPIPorts/Example2_MoreSPIPorts.ino index 5bc05c0..1dc8581 100644 --- a/libraries/SPI/examples/Example2_MoreSPIPorts/Example2_MoreSPIPorts.ino +++ b/libraries/SPI/examples/Example2_MoreSPIPorts/Example2_MoreSPIPorts.ino @@ -17,8 +17,8 @@ SPISettings mySettings(SPI_SPEED, SPI_ORDER, SPI_MODE); const char *msg = "Hello world!"; -//SPIClass SPI(); //This is default and automatically defined on RedBoard/ATP/Nano. Uses pads 5/6/7 (SCK/MISO/MOSI). -SPIClass SPI1(1); //Use IO Master 1 on pads 8/9/10 +//SPIClass SPI(); //This is default and automatically defined on RedBoard/ATP/Nano. Access using pins labeled SCK/MISO/MOSI (connects to pads 5/6/7 on module). +SPIClass SPI1(1); //Use IO Master 1 on pads 8/9/10. See schematic of your board for pin locations. // SPIClass mySPI(2); //Use IO Master 2 on pads 27/25/28 // SPIClass anotherSPI(3); //Use IO Master 3 on pads 42/43/44 // SPIClass SPI4(4); //Use IO Master 4 on pads 39/40/38