aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/test-spi-roundtrip.cpp89
1 files changed, 43 insertions, 46 deletions
diff --git a/examples/test-spi-roundtrip.cpp b/examples/test-spi-roundtrip.cpp
index 257303b..8fe97b9 100644
--- a/examples/test-spi-roundtrip.cpp
+++ b/examples/test-spi-roundtrip.cpp
@@ -4,7 +4,7 @@
* Bob is nowhere to be found, so Alice decides to talk to herself.
*
* Instructions: Connect SPI2 (Alice) to herself (i.e., MISO to MOSI).
- * Connect to Alice via Serial2 at 115200 baud. Press any key to start.
+ * Connect to Alice via SerialUSB. Press any key to start.
*
* Alice will talk to herself for a little while. The sketch will
* report if Alice can't hear anything she says. She'll then start
@@ -37,13 +37,13 @@ const SPIFrequency spi_freqs[] = {
uint8 test_buf[TEST_BUF_SIZE] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
void bad_assert(const char* file, int line, const char* exp) {
- Serial2.println();
- Serial2.print("ERROR: FAILED ASSERT(");
- Serial2.print(exp);
- Serial2.print("): ");
- Serial2.print(file);
- Serial2.print(": ");
- Serial2.println(line);
+ SerialUSB.println();
+ SerialUSB.print("ERROR: FAILED ASSERT(");
+ SerialUSB.print(exp);
+ SerialUSB.print("): ");
+ SerialUSB.print(file);
+ SerialUSB.print(": ");
+ SerialUSB.println(line);
throb();
}
@@ -59,26 +59,23 @@ void soliloquies(uint32 bitOrder);
void setup() {
pinMode(BOARD_LED_PIN, OUTPUT);
- Serial2.begin(115200);
- Serial2.println();
- Serial2.print("** SPI test ready. Press any key to start.");
- while (!Serial2.available())
+ while (!SerialUSB.available())
;
- Serial2.read();
+ SerialUSB.read();
}
void loop() {
- Serial2.println("** Having a conversation, MSB first");
+ SerialUSB.println("** Having a conversation, MSB first");
haveConversation(MSBFIRST);
- Serial2.println("** Having a conversation, LSB first");
+ SerialUSB.println("** Having a conversation, LSB first");
haveConversation(LSBFIRST);
- Serial2.println();
- Serial2.println("*** All done! It looks like everything worked.");
- Serial2.println();
+ SerialUSB.println();
+ SerialUSB.println("*** All done! It looks like everything worked.");
+ SerialUSB.println();
- Serial2.println("** Alice will now wax eloquent in various styles. "
+ SerialUSB.println("** Alice will now wax eloquent in various styles. "
"Press any key for the next configuration.");
soliloquies(MSBFIRST);
soliloquies(LSBFIRST);
@@ -100,28 +97,28 @@ void haveConversation(uint32 bitOrder) {
}
void chat(SPIFrequency frequency, uint32 bitOrder, uint32 mode) {
- Serial2.print("Having a chat.\tFrequency: ");
+ SerialUSB.print("Having a chat.\tFrequency: ");
printFrequencyString(frequency);
- Serial2.print(",\tbitOrder: ");
- Serial2.print(bitOrder == MSBFIRST ? "MSB" : "LSB");
- Serial2.print(",\tmode: ");
- Serial2.print(mode);
- Serial2.print(".");
+ SerialUSB.print(",\tbitOrder: ");
+ SerialUSB.print(bitOrder == MSBFIRST ? "MSB" : "LSB");
+ SerialUSB.print(",\tmode: ");
+ SerialUSB.print(mode);
+ SerialUSB.print(".");
- Serial2.print(" [1] ");
+ SerialUSB.print(" [1] ");
alice.begin(frequency, bitOrder, mode);
- Serial2.print(" [2] ");
+ SerialUSB.print(" [2] ");
uint32 txed = 0;
while (txed < TEST_BUF_SIZE) {
ASSERT(alice.transfer(test_buf[txed]) == test_buf[txed]);
txed++;
}
- Serial2.print(" [3] ");
+ SerialUSB.print(" [3] ");
alice.end();
- Serial2.println(" ok.");
+ SerialUSB.println(" ok.");
}
void soliloquy(SPIFrequency freq, uint32 bitOrder, uint32 mode);
@@ -136,48 +133,48 @@ void soliloquies(uint32 bitOrder) {
void soliloquy(SPIFrequency frequency, uint32 bitOrder, uint32 mode) {
const uint8 repeat = 0xAE;
- Serial2.print("Alice is giving a soliloquy (repeating 0x");
- Serial2.print(repeat, HEX);
- Serial2.print("). Frequency: ");
+ SerialUSB.print("Alice is giving a soliloquy (repeating 0x");
+ SerialUSB.print(repeat, HEX);
+ SerialUSB.print("). Frequency: ");
printFrequencyString(frequency);
- Serial2.print(", bitOrder: ");
- Serial2.print(bitOrder == MSBFIRST ? "big-endian" : "little-endian");
- Serial2.print(", SPI mode: ");
- Serial2.println(mode);
+ SerialUSB.print(", bitOrder: ");
+ SerialUSB.print(bitOrder == MSBFIRST ? "big-endian" : "little-endian");
+ SerialUSB.print(", SPI mode: ");
+ SerialUSB.println(mode);
alice.begin(frequency, bitOrder, mode);
- while (!Serial2.available()) {
+ while (!SerialUSB.available()) {
alice.write(repeat);
delayMicroseconds(200);
}
- Serial2.read();
+ SerialUSB.read();
}
void printFrequencyString(SPIFrequency frequency) {
switch (frequency) {
case SPI_18MHZ:
- Serial2.print("18 MHz");
+ SerialUSB.print("18 MHz");
break;
case SPI_9MHZ:
- Serial2.print("9 MHz");
+ SerialUSB.print("9 MHz");
break;
case SPI_4_5MHZ:
- Serial2.print("4.5 MHz");
+ SerialUSB.print("4.5 MHz");
break;
case SPI_2_25MHZ:
- Serial2.print("2.25 MHZ");
+ SerialUSB.print("2.25 MHZ");
break;
case SPI_1_125MHZ:
- Serial2.print("1.125 MHz");
+ SerialUSB.print("1.125 MHz");
break;
case SPI_562_500KHZ:
- Serial2.print("562.500 KHz");
+ SerialUSB.print("562.500 KHz");
break;
case SPI_281_250KHZ:
- Serial2.print("281.250 KHz");
+ SerialUSB.print("281.250 KHz");
break;
case SPI_140_625KHZ:
- Serial2.print("140.625 KHz");
+ SerialUSB.print("140.625 KHz");
break;
}
}