Updated BA2 1MEM example

pull/1/head
Steve Lascos 7 years ago
parent ecb0ba0aa8
commit 988174912b
  1. 80
      examples/BA2_TGA_Pro_1MEM/BA2_TGA_Pro_1MEM.ino

@ -8,9 +8,13 @@
* This demo will provide an audio passthrough, as well as exercise the * This demo will provide an audio passthrough, as well as exercise the
* MIDI interface. * MIDI interface.
* *
* It will also perform a sweeo of the SPI MEM0 external RAM. * It will also peform a sweep of SPI MEM0.
*
* NOTE: SPI MEM0 can be used by a Teensy 3.1/3.2/3.5/3.6.
* pins.
* *
*/ */
//#include <i2c_t3.h>
#include <Wire.h> #include <Wire.h>
#include <Audio.h> #include <Audio.h>
#include <MIDI.h> #include <MIDI.h>
@ -19,7 +23,6 @@
MIDI_CREATE_DEFAULT_INSTANCE(); MIDI_CREATE_DEFAULT_INSTANCE();
using namespace midi; using namespace midi;
using namespace BAGuitar; using namespace BAGuitar;
AudioInputI2S i2sIn; AudioInputI2S i2sIn;
@ -32,23 +35,25 @@ AudioConnection patch1(i2sIn,1, i2sOut, 1);
BAAudioControlWM8731 codecControl; BAAudioControlWM8731 codecControl;
BAGpio gpio; // access to User LED BAGpio gpio; // access to User LED
BASpiMemory spiMem0(SpiDeviceId::SPI_DEVICE0); BASpiMemory spiMem0(SpiDeviceId::SPI_DEVICE0);
BASpiMemory spiMem1(SpiDeviceId::SPI_DEVICE1);
unsigned long t=0; unsigned long t=0;
// SPI stuff // SPI stuff
int spiAddress0 = 0; int spiAddress0 = 0;
int spiData0 = 0xff; uint16_t spiData0 = 0xABCD;
int spiErrorCount0 = 0; int spiErrorCount0 = 0;
int spiAddress1 = 0;
int spiData1 = 0xff;
int spiErrorCount1 = 0;
constexpr int mask0 = 0x5555;
constexpr int mask1 = 0xaaaa;
int maskPhase = 0;
int loopPhase = 0;
void setup() { void setup() {
MIDI.begin(MIDI_CHANNEL_OMNI); MIDI.begin(MIDI_CHANNEL_OMNI);
Serial.begin(57600); Serial.begin(57600);
while (!Serial) {}
delay(5); delay(5);
// If the codec was already powered up (due to reboot) power itd own first // If the codec was already powered up (due to reboot) power itd own first
@ -56,10 +61,36 @@ void setup() {
delay(100); delay(100);
AudioMemory(24); AudioMemory(24);
Serial.println("Enabling codec...\n"); Serial.println("Sketch: Enabling codec...\n");
codecControl.enable(); codecControl.enable();
delay(100); delay(100);
Serial.println("Enabling SPI");
spiMem0.begin();
}
int calcData(int spiAddress, int loopPhase, int maskPhase)
{
int data;
int phase = ((loopPhase << 1) + maskPhase) & 0x3;
switch(phase)
{
case 0 :
data = spiAddress ^ mask0;
break;
case 1:
data = spiAddress ^ mask1;
break;
case 2:
data = ~spiAddress ^ mask0;
break;
case 3:
data = ~spiAddress ^ mask1;
}
return (data & 0xffff);
} }
void loop() { void loop() {
@ -67,15 +98,16 @@ void loop() {
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// Write test data to the SPI Memory 0 // Write test data to the SPI Memory 0
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
for (spiAddress0=0; spiAddress0 <= SPI_MAX_ADDR; spiAddress0++) { maskPhase = 0;
for (spiAddress0=0; spiAddress0 <= SPI_MAX_ADDR; spiAddress0=spiAddress0+2) {
if ((spiAddress0 % 32768) == 0) { if ((spiAddress0 % 32768) == 0) {
//Serial.print("Writing to "); //Serial.print("Writing to ");
//Serial.println(spiAddress0, HEX); //Serial.println(spiAddress0, HEX);
} }
//mem0Write(spiAddress0, spiData0); spiData0 = calcData(spiAddress0, loopPhase, maskPhase);
spiMem0.write(spiAddress0, spiData0); spiMem0.write16(spiAddress0, spiData0);
spiData0 = (spiData0-1) & 0xff; maskPhase = (maskPhase+1) % 2;
} }
Serial.println("SPI0 writing DONE!"); Serial.println("SPI0 writing DONE!");
@ -84,32 +116,33 @@ void loop() {
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
spiErrorCount0 = 0; spiErrorCount0 = 0;
spiAddress0 = 0; spiAddress0 = 0;
spiData0 = 0xff; maskPhase = 0;
for (spiAddress0=0; spiAddress0 <= SPI_MAX_ADDR; spiAddress0++) { for (spiAddress0=0; spiAddress0 <= SPI_MAX_ADDR; spiAddress0=spiAddress0+2) {
if ((spiAddress0 % 32768) == 0) { if ((spiAddress0 % 32768) == 0) {
//Serial.print("Reading "); // Serial.print("Reading ");
//Serial.print(spiAddress0, HEX); // Serial.print(spiAddress0, HEX);
} }
//int data = mem0Read(spiAddress0); spiData0 = calcData(spiAddress0, loopPhase, maskPhase);
int data = spiMem0.read(spiAddress0); int data = spiMem0.read16(spiAddress0);
if (data != spiData0) { if (data != spiData0) {
spiErrorCount0++; spiErrorCount0++;
Serial.println(""); Serial.println("");
Serial.print("ERROR MEM0: (expected) (actual):"); Serial.print("ERROR MEM0: (expected) (actual):");
Serial.print(spiData0, HEX); Serial.print(":"); Serial.print(spiData0, HEX); Serial.print(":");
Serial.println(data, HEX); Serial.print(data, HEX);
delay(100); delay(100);
} }
maskPhase = (maskPhase+1) % 2;
if ((spiAddress0 % 32768) == 0) { if ((spiAddress0 % 32768) == 0) {
//Serial.print(", data = "); // Serial.print(", data = ");
//Serial.println(data, HEX); // Serial.println(data, HEX);
// Serial.println(String(" loopPhase: ") + loopPhase + String(" maskPhase: ") + maskPhase);
} }
spiData0 = (spiData0-1) & 0xff;
// Break out of test once the error count reaches 10 // Break out of test once the error count reaches 10
if (spiErrorCount0 > 10) { break; } if (spiErrorCount0 > 10) { break; }
@ -117,6 +150,7 @@ void loop() {
if (spiErrorCount0 == 0) { Serial.println("SPI0 TEST PASSED!!!"); } if (spiErrorCount0 == 0) { Serial.println("SPI0 TEST PASSED!!!"); }
loopPhase = (loopPhase+1) % 2;
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
// MIDI TESTING // MIDI TESTING

Loading…
Cancel
Save