Skip to content

Commit ab8ed1c

Browse files
author
Owen
authored
Merge pull request #117 from sparkfun/addSPIExamples
Add example configuring alternate SPI ports.
2 parents f2e2d68 + bc0c12e commit ab8ed1c

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

libraries/SPI/examples/Example1_SPI/Example1_SPI.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const char *msg = "Hello world!";
2020
void setup()
2121
{
2222

23-
Serial.begin(9600);
23+
Serial.begin(115200);
2424
while (!Serial)
2525
{
2626
}; //Wait for user to open terminal window
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* Author: Owen Lyke
2+
Created: May 13 2019
3+
License: MIT. See SparkFun Arduino Apollo3 Project for more information
4+
5+
This example demonstrates how to use Arduino SPI
6+
*/
7+
8+
#include "SPI.h"
9+
10+
#define CS_PIN 2
11+
12+
#define SPI_SPEED 1000000
13+
#define SPI_ORDER MSBFIRST
14+
#define SPI_MODE SPI_MODE0
15+
16+
SPISettings mySettings(SPI_SPEED, SPI_ORDER, SPI_MODE);
17+
18+
const char *msg = "Hello world!";
19+
20+
//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).
21+
SPIClass SPI1(1); //Use IO Master 1 on pads 8/9/10. See schematic of your board for pin locations.
22+
// SPIClass mySPI(2); //Use IO Master 2 on pads 27/25/28
23+
// SPIClass anotherSPI(3); //Use IO Master 3 on pads 42/43/44
24+
// SPIClass SPI4(4); //Use IO Master 4 on pads 39/40/38
25+
// SPIClass SPI5(5); //Use IO Master 5 on pads 48/49/47
26+
27+
void setup()
28+
{
29+
Serial.begin(115200);
30+
while (!Serial)
31+
{
32+
}; //Wait for user to open terminal window
33+
34+
Serial.println("SparkFun Arduino Apollo3 SPI Example");
35+
Serial.printf("Compiled on %s, %s\n\n", __DATE__, __TIME__);
36+
37+
SPI1.begin();
38+
39+
pinMode(CS_PIN, OUTPUT);
40+
}
41+
42+
void loop()
43+
{
44+
digitalWrite(CS_PIN, LOW);
45+
SPI1.beginTransaction(mySettings);
46+
SPI1.transfer(0xAA);
47+
SPI1.endTransaction();
48+
49+
SPI1.beginTransaction(mySettings);
50+
SPI1.transferOut((void *)msg, strlen(msg));
51+
SPI1.endTransaction();
52+
digitalWrite(CS_PIN, HIGH);
53+
delay(1000);
54+
}

0 commit comments

Comments
 (0)