0

Adafruit_ZeroI2S.h read() behaviour
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Adafruit_ZeroI2S.h read() behaviour

by btkjnqw on Thu Feb 14, 2019 4:32 pm

Hi, I am using the Adafruit_ZeroI2S.h library on a Feather M0 LoRa (3178) in conjunction with one ICS43432 I2S microphone. Lacking an example how to use read(left,right), I wrote the code below. However, I am experiencing some weird behaviour: sometimes the data comes in in the left, sometimes in the right variable. Since in the implementation of the read() function, left and right are subsequently read from the same register, I assume that somehow one data point is missed and subsequently the following datapoints get "assigned" to the wrong variable.

Please advice on how to prevent this from happening. Thanks!

Code: Select all | TOGGLE FULL SIZE
/*
  wjmb: testcode for Feather_M0 with ICS43432.
 */

#include <Adafruit_ZeroFFT.h> // https://github.com/adafruit/Adafruit_ZeroFFT
#include <Adafruit_ZeroI2S.h> // https://github.com/adafruit/Adafruit_ZeroI2S
#include <math.h>

/* max volume for 32 bit data */
#define VOLUME ( (1UL << 31) - 1)

#define REDLED 13

#define SAMPLE_RATE 12500
#define DATA_SIZE 512

/* create a buffer for both the left and right channel data */
int32_t left[DATA_SIZE];
int32_t right[DATA_SIZE];

Adafruit_ZeroI2S i2s(0, 1, 9, 2);

void blink(int speed)
{
  digitalWrite(REDLED, HIGH);
  delay(speed);
  digitalWrite(REDLED, LOW);
  delay(speed);
}

void get_audiosample()
{
  for (unsigned i=0; i<DATA_SIZE; ++i) i2s.read(&left[i], &right[i]);
}

void setup() {
  pinMode(REDLED, OUTPUT);
  delay(10000);
  Serial.begin(115200);
  i2s.begin(I2S_32_BIT, SAMPLE_RATE);
  i2s.enableRx();
}
 
void loop() {
  //i2s.enableRx();
  blink(100);
  get_audiosample();
  blink(20);
  //i2s.disableRx();
  for (int i = 0; i<DATA_SIZE; i++)
  {
    left[i] >>= 7;
    right[i] >>= 7;
  }
  // FOR SOME REALLY ODD REASON, DATA COMES IN TWICE SOMETIME ON THE LEFT AND SOMETIMES ON THE RIGHT CHANNEL.
  for (int i = 0; i<DATA_SIZE; i++) { Serial.print(left[i]); Serial.print("\t"); Serial.println(right[i]); }
  Serial.println();
  delay(2000);
}

btkjnqw
 
Posts: 2
Joined: Thu Aug 16, 2018 1:37 am

Please be positive and constructive with your questions and comments.