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. Uses pads 5/6/7 (SCK/MISO/MOSI).
21
+ SPIClass SPI1 (1 ); // Use IO Master 1 on pads 8/9/10
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