   ///////////////////////////////////////////////////////////////////
   spiErrorCount0 = 0;
   spiAddress0 = 0;
-  spiData0 = 0xff;
-
-  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("Reading ");
-      //Serial.print(spiAddress0, HEX);
-    }
-
-    //int data = mem0Read(spiAddress0);
-    int data = spiMem0.read(spiAddress0);
+//      Serial.print("Reading ");
+//      Serial.print(spiAddress0, HEX);
+    }
+
+    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);
-    }
-
-    spiData0 = (spiData0-1) & 0xff;
+//      Serial.print(", data = ");
+//      Serial.println(data, HEX);
+//      Serial.println(String(" loopPhase: ") + loopPhase + String(" maskPhase: ") + maskPhase);
+    }
 
     // Break out of test once the error count reaches 10
     if (spiErrorCount0 > 10) { break; }

  delay(100);
  AudioMemory(24);

  Serial.println("Enabling codec...\n");
  codecControl.enable();
  delay(100);
  
}

void loop() {  

  //////////////////////////////////////////////////////////////////
  // Write test data to the SPI Memory 0
  //////////////////////////////////////////////////////////////////
  for (spiAddress0=0; spiAddress0 <= SPI_MAX_ADDR; spiAddress0++) {
    if ((spiAddress0 % 32768) == 0) {
      //Serial.print("Writing to ");
      //Serial.println(spiAddress0, HEX);
    }

    //mem0Write(spiAddress0, spiData0);
    spiMem0.write(spiAddress0, spiData0);
    spiData0 = (spiData0-1) & 0xff;
  }
  Serial.println("SPI0 writing DONE!");


BAAudioControlWM8731      codecControl;
BAGpio                    gpio;  // access to User LED
BASpiMemory               spiMem0(SpiDeviceId::SPI_DEVICE0);

unsigned long t=0;

// SPI stuff
int spiAddress0 = 0;
uint16_t spiData0 = 0xABCD;
int spiErrorCount0 = 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
