|
|
|
@ -15,6 +15,7 @@ |
|
|
|
|
* pins. |
|
|
|
|
*
|
|
|
|
|
*/ |
|
|
|
|
//#include <i2c_t3.h>
|
|
|
|
|
#include <Wire.h> |
|
|
|
|
#include <Audio.h> |
|
|
|
|
#include <MIDI.h> |
|
|
|
@ -41,17 +42,24 @@ unsigned long t=0; |
|
|
|
|
|
|
|
|
|
// SPI stuff
|
|
|
|
|
int spiAddress0 = 0; |
|
|
|
|
int spiData0 = 0xff; |
|
|
|
|
uint16_t spiData0 = 0xABCD; |
|
|
|
|
int spiErrorCount0 = 0; |
|
|
|
|
|
|
|
|
|
int spiAddress1 = 0; |
|
|
|
|
int spiData1 = 0xff; |
|
|
|
|
uint16_t spiData1 = 0xDCBA; |
|
|
|
|
int spiErrorCount1 = 0; |
|
|
|
|
|
|
|
|
|
constexpr int mask0 = 0x5555; |
|
|
|
|
constexpr int mask1 = 0xaaaa; |
|
|
|
|
|
|
|
|
|
int maskPhase = 0; |
|
|
|
|
int loopPhase = 0; |
|
|
|
|
|
|
|
|
|
void setup() { |
|
|
|
|
|
|
|
|
|
MIDI.begin(MIDI_CHANNEL_OMNI); |
|
|
|
|
Serial.begin(57600); |
|
|
|
|
while (!Serial) {} |
|
|
|
|
delay(5); |
|
|
|
|
|
|
|
|
|
// If the codec was already powered up (due to reboot) power itd own first
|
|
|
|
@ -59,10 +67,37 @@ void setup() { |
|
|
|
|
delay(100); |
|
|
|
|
AudioMemory(24); |
|
|
|
|
|
|
|
|
|
Serial.println("Enabling codec...\n"); |
|
|
|
|
Serial.println("Sketch: Enabling codec...\n"); |
|
|
|
|
codecControl.enable(); |
|
|
|
|
delay(100); |
|
|
|
|
|
|
|
|
|
Serial.println("Enabling SPI"); |
|
|
|
|
spiMem0.begin(); |
|
|
|
|
spiMem1.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() { |
|
|
|
@ -70,15 +105,16 @@ void loop() { |
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
// 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) { |
|
|
|
|
//Serial.print("Writing to ");
|
|
|
|
|
//Serial.println(spiAddress0, HEX);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//mem0Write(spiAddress0, spiData0);
|
|
|
|
|
spiMem0.write(spiAddress0, spiData0); |
|
|
|
|
spiData0 = (spiData0-1) & 0xff; |
|
|
|
|
spiData0 = calcData(spiAddress0, loopPhase, maskPhase); |
|
|
|
|
spiMem0.write16(spiAddress0, spiData0); |
|
|
|
|
maskPhase = (maskPhase+1) % 2; |
|
|
|
|
} |
|
|
|
|
Serial.println("SPI0 writing DONE!"); |
|
|
|
|
|
|
|
|
@ -87,32 +123,33 @@ void loop() { |
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
|
spiErrorCount0 = 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) { |
|
|
|
|
//Serial.print("Reading ");
|
|
|
|
|
//Serial.print(spiAddress0, HEX);
|
|
|
|
|
// Serial.print("Reading ");
|
|
|
|
|
// Serial.print(spiAddress0, HEX);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//int data = mem0Read(spiAddress0);
|
|
|
|
|
int data = spiMem0.read(spiAddress0); |
|
|
|
|
spiData0 = calcData(spiAddress0, loopPhase, maskPhase); |
|
|
|
|
int data = spiMem0.read16(spiAddress0); |
|
|
|
|
if (data != spiData0) { |
|
|
|
|
spiErrorCount0++; |
|
|
|
|
Serial.println(""); |
|
|
|
|
Serial.print("ERROR MEM0: (expected) (actual):"); |
|
|
|
|
Serial.print(spiData0, HEX); Serial.print(":"); |
|
|
|
|
Serial.println(data, HEX); |
|
|
|
|
Serial.print(data, HEX); |
|
|
|
|
|
|
|
|
|
delay(100); |
|
|
|
|
} |
|
|
|
|
maskPhase = (maskPhase+1) % 2; |
|
|
|
|
|
|
|
|
|
if ((spiAddress0 % 32768) == 0) { |
|
|
|
|
//Serial.print(", data = ");
|
|
|
|
|
//Serial.println(data, HEX);
|
|
|
|
|
// Serial.print(", data = ");
|
|
|
|
|
// 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
|
|
|
|
|
if (spiErrorCount0 > 10) { break; } |
|
|
|
|
|
|
|
|
@ -124,15 +161,16 @@ void loop() { |
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
// Write test data to the SPI Memory 1
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
for (spiAddress1=0; spiAddress1 <= SPI_MAX_ADDR; spiAddress1++) { |
|
|
|
|
maskPhase = 0; |
|
|
|
|
for (spiAddress1=0; spiAddress1 <= SPI_MAX_ADDR; spiAddress1+=2) { |
|
|
|
|
if ((spiAddress1 % 32768) == 0) { |
|
|
|
|
//Serial.print("Writing to ");
|
|
|
|
|
//Serial.println(spiAddress1, HEX);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//mem0Write(spiAddress1, spiData1);
|
|
|
|
|
spiMem1.write(spiAddress1, spiData1); |
|
|
|
|
spiData1 = (spiData1-1) & 0xff; |
|
|
|
|
spiData1 = calcData(spiAddress1, loopPhase, maskPhase); |
|
|
|
|
spiMem1.write16(spiAddress1, spiData1); |
|
|
|
|
maskPhase = (maskPhase+1) % 2; |
|
|
|
|
} |
|
|
|
|
Serial.println("SPI1 writing DONE!"); |
|
|
|
|
|
|
|
|
@ -141,15 +179,16 @@ void loop() { |
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
|
spiErrorCount1 = 0; |
|
|
|
|
spiAddress1 = 0; |
|
|
|
|
spiData1 = 0xff; |
|
|
|
|
|
|
|
|
|
for (spiAddress1=0; spiAddress1 <= SPI_MAX_ADDR; spiAddress1++) { |
|
|
|
|
maskPhase = 0; |
|
|
|
|
for (spiAddress1=0; spiAddress1 <= SPI_MAX_ADDR; spiAddress1+=2) { |
|
|
|
|
if ((spiAddress1 % 32768) == 0) { |
|
|
|
|
//Serial.print("Reading ");
|
|
|
|
|
//Serial.print(spiAddress1, HEX);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int data = spiMem1.read(spiAddress1); |
|
|
|
|
spiData1 = calcData(spiAddress1, loopPhase, maskPhase); |
|
|
|
|
uint16_t data = spiMem1.read16(spiAddress1); |
|
|
|
|
if (data != spiData1) { |
|
|
|
|
spiErrorCount1++; |
|
|
|
|
Serial.println(""); |
|
|
|
@ -158,14 +197,13 @@ void loop() { |
|
|
|
|
Serial.println(data, HEX); |
|
|
|
|
delay(100); |
|
|
|
|
} |
|
|
|
|
maskPhase = (maskPhase+1) % 2; |
|
|
|
|
|
|
|
|
|
if ((spiAddress1 % 32768) == 0) { |
|
|
|
|
//Serial.print(", data = ");
|
|
|
|
|
//Serial.println(data, HEX);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
spiData1 = (spiData1-1) & 0xff; |
|
|
|
|
|
|
|
|
|
// Break out of test once the error count reaches 10
|
|
|
|
|
if (spiErrorCount1 > 10) { break; } |
|
|
|
|
|
|
|
|
@ -173,7 +211,7 @@ void loop() { |
|
|
|
|
|
|
|
|
|
if (spiErrorCount1 == 0) { Serial.println("SPI1 TEST PASSED!!!"); } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loopPhase = (loopPhase+1) % 2; |
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
// MIDI TESTING
|