-
Notifications
You must be signed in to change notification settings - Fork 39
Add example configuring alternate SPI ports. #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
54 changes: 54 additions & 0 deletions
54
libraries/SPI/examples/Example2_MoreSPIPorts/Example2_MoreSPIPorts.ino
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a nit: you are correctly using the pad vs pin notation but perhaps a user would not understand that pads 5/6/7 are actually (13, 12, 11) on the RedBoard (w/ Uno pin naming scheme).
Should there be a note explaining this in this example?