Xiao SAMD21 I2S/INMP441 Serial Outputting too man zeros

##Fix listed below##

Attempting to get a clean I2S signal out from an inmp441 board but kind of stuck. I know it may not be officially supported as I2S on the SAMD21 variant seems to have been disabled from factory.

I am able to get I2S to initialized and audio recorded with either the variant included I2S library and AdafruitZero I2s library.

I am experiencing the audio signal coming in with also many zeros in a row being thrown in the serial monitor. I have constant noise happening in the office so I think it has something to do with the buffered data or the 16 bit shifting from 32bits. Programming isn’t my expertise but cant seem to find much support on the topic.

If I code in the following, serial output does not occur at all.

    i2s.read(&sampleL, &sampleR);
    
    micIn = sampleL;                                               // Read in

    if(micIn == 0) return;

Any help or direction would be greatly appreciated. I like this board for the projects I need that don’t require wifi/BLE. Will calculate fft data and drive LEDs once I can clean up the incoming signal.

Code:

// For testing this library with the INMP441 with the Xiao SAMD21

#include <Adafruit_ZeroI2S.h>

#define SAMPLING_FREQ 30000

int32_t sampleL = 0;
int32_t sampleR = 0;
int16_t sample = 0;
uint8_t squelch = 100;

Adafruit_ZeroI2S i2s;

void setup() {
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  i2s.begin(I2S_32_BIT, SAMPLING_FREQ);
  i2s.enableRx();
}

void loop() {
  // put your main code here, to run repeatedly:
  getSampleI2S();
}

void getSampleI2S() {
  //
  int32_t micIn;

  if(i2s.rxReady()) {

    i2s.read(&sampleL, &sampleR);
    
    micIn = sampleL;                                               // Read in

    sample = micIn >> 16;


    //------------ Oscilloscope output ---------------------------
          Serial.print(sample); Serial.print(" ");
          Serial.print(1500); Serial.print(" ");
          Serial.print(-1500); Serial.print(" ");
          Serial.println(" ");
  }
}

Checked the AdafruitI2S library github and a user mentioned an issue with the interrupts and this library.

He recommended commenting out the RXRDY0 INFLAG lines in the while loop. That has worked and I can get a steady stream of mono data without the plethora of zeros.

Original comment and link below.

https://github.com/adafruit/Adafruit_ZeroI2S/issues/12

I think I figured out the issue, something about mono messes with the interrupts. The regular I2S lib does not check the interrupts, but this one does on the blocking read. This results in some weird behaviour that I have not been able to figure out. If you remove the checks on I2S->INTFLAG.bit.RXRDY0 from the while loops the blocking reads work perfectly.

Hello, thanks for your feedback and support for the forum!

We have published a contrbutor wanted program, you can change the wiki contents, accept some assignments or share your thoughts with us. We will offer a range of rewards to our contributors.