|
|
@ -15,6 +15,7 @@ |
|
|
|
* pins. |
|
|
|
* pins. |
|
|
|
*
|
|
|
|
*
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
//#include <i2c_t3.h>
|
|
|
|
#include <Wire.h> |
|
|
|
#include <Wire.h> |
|
|
|
#include <Audio.h> |
|
|
|
#include <Audio.h> |
|
|
|
#include <MIDI.h> |
|
|
|
#include <MIDI.h> |
|
|
@ -41,17 +42,24 @@ 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 spiAddress1 = 0; |
|
|
|
int spiData1 = 0xff; |
|
|
|
uint16_t spiData1 = 0xDCBA; |
|
|
|
int spiErrorCount1 = 0; |
|
|
|
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
|
|
|
@ -59,26 +67,54 @@ 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(); |
|
|
|
|
|
|
|
spiMem1.begin(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
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() { |
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// 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!"); |
|
|
|
|
|
|
|
|
|
|
@ -87,32 +123,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; } |
|
|
|
|
|
|
|
|
|
|
@ -124,15 +161,16 @@ void loop() { |
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Write test data to the SPI Memory 1
|
|
|
|
// 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) { |
|
|
|
if ((spiAddress1 % 32768) == 0) { |
|
|
|
//Serial.print("Writing to ");
|
|
|
|
//Serial.print("Writing to ");
|
|
|
|
//Serial.println(spiAddress1, HEX);
|
|
|
|
//Serial.println(spiAddress1, HEX);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//mem0Write(spiAddress1, spiData1);
|
|
|
|
spiData1 = calcData(spiAddress1, loopPhase, maskPhase); |
|
|
|
spiMem1.write(spiAddress1, spiData1); |
|
|
|
spiMem1.write16(spiAddress1, spiData1); |
|
|
|
spiData1 = (spiData1-1) & 0xff; |
|
|
|
maskPhase = (maskPhase+1) % 2; |
|
|
|
} |
|
|
|
} |
|
|
|
Serial.println("SPI1 writing DONE!"); |
|
|
|
Serial.println("SPI1 writing DONE!"); |
|
|
|
|
|
|
|
|
|
|
@ -141,15 +179,16 @@ void loop() { |
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
spiErrorCount1 = 0; |
|
|
|
spiErrorCount1 = 0; |
|
|
|
spiAddress1 = 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) { |
|
|
|
if ((spiAddress1 % 32768) == 0) { |
|
|
|
//Serial.print("Reading ");
|
|
|
|
//Serial.print("Reading ");
|
|
|
|
//Serial.print(spiAddress1, HEX);
|
|
|
|
//Serial.print(spiAddress1, HEX);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int data = spiMem1.read(spiAddress1); |
|
|
|
spiData1 = calcData(spiAddress1, loopPhase, maskPhase); |
|
|
|
|
|
|
|
uint16_t data = spiMem1.read16(spiAddress1); |
|
|
|
if (data != spiData1) { |
|
|
|
if (data != spiData1) { |
|
|
|
spiErrorCount1++; |
|
|
|
spiErrorCount1++; |
|
|
|
Serial.println(""); |
|
|
|
Serial.println(""); |
|
|
@ -158,14 +197,13 @@ void loop() { |
|
|
|
Serial.println(data, HEX); |
|
|
|
Serial.println(data, HEX); |
|
|
|
delay(100); |
|
|
|
delay(100); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
maskPhase = (maskPhase+1) % 2; |
|
|
|
|
|
|
|
|
|
|
|
if ((spiAddress1 % 32768) == 0) { |
|
|
|
if ((spiAddress1 % 32768) == 0) { |
|
|
|
//Serial.print(", data = ");
|
|
|
|
//Serial.print(", data = ");
|
|
|
|
//Serial.println(data, HEX);
|
|
|
|
//Serial.println(data, HEX);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
spiData1 = (spiData1-1) & 0xff; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Break out of test once the error count reaches 10
|
|
|
|
// Break out of test once the error count reaches 10
|
|
|
|
if (spiErrorCount1 > 10) { break; } |
|
|
|
if (spiErrorCount1 > 10) { break; } |
|
|
|
|
|
|
|
|
|
|
@ -173,7 +211,7 @@ void loop() { |
|
|
|
|
|
|
|
|
|
|
|
if (spiErrorCount1 == 0) { Serial.println("SPI1 TEST PASSED!!!"); } |
|
|
|
if (spiErrorCount1 == 0) { Serial.println("SPI1 TEST PASSED!!!"); } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loopPhase = (loopPhase+1) % 2; |
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// MIDI TESTING
|
|
|
|
// MIDI TESTING
|