earlephilhower / arduino-pico

Raspberry Pi Pico Arduino core, for all RP2040 and RP2350 boards
GNU Lesser General Public License v2.1
2.06k stars 431 forks source link

Issue with I2S Input from V4220M/CS4220 Audio Codec #2611

Open kurogedelic opened 12 hours ago

kurogedelic commented 12 hours ago

Hello. First, I should mention that I'm not an I2S expert, so I might be missing something fundamental. I'm trying to receive audio data from a V4220M/CS4220 codec using the Arduino-Pico I2S library, but I'm experiencing issues with the input data. Interestingly, I2S output to the same codec works perfectly fine.

Hardware Setup:

Clock Configuration:

Code:

I2S i2s(INPUT);
const int32_t sampleRate = 48000;

void setup() {
    // V4220M reset sequence
    pinMode(PIN_I2S_RST, OUTPUT);
    digitalWrite(PIN_I2S_RST, LOW);
    delay(10);
    digitalWrite(PIN_I2S_RST, HIGH);
    delay(50);

    // I2S configuration
    i2s.setBCLK(PIN_I2S_BCLK);
    i2s.setDATA(PIN_I2S_DIN);
    i2s.setBitsPerSample(32);
    i2s.setBuffers(4, 32);
    i2s.setMCLK(PIN_I2S_MCLK);
    i2s.setMCLKmult(256);

    if (!i2s.setSysClk(sampleRate)) {
        Serial.println("Failed to set system clock!");
        while(1);
    }

    if (!i2s.begin(sampleRate)) {
        Serial.println("Failed to start I2S!");
        while(1);
    }
}

The received data shows an unusual pattern:

Time,Raw,Hex,Voltage,Debug
82087,14,0x00000E,0.000,0x00000ED0
82087,262141,0x03FFFD,0.062,0x03FFFD74
82087,7,0x000007,0.000,0x00000728
82088,262121,0x03FFE9,0.062,0x03FFE9A8

The data seems to alternate between very small values (0x00000X) and larger values (0x03FFXX), which doesn't look like normal audio data. I've tried:

  1. Different bit depths (24/32)
  2. Different I2S formats (DIF0/DIF1 configurations on V4220M)
  3. Checking clock signals with oscilloscope
  4. Multiple codec chips to rule out hardware issues

The fact that output works perfectly suggests the clock setup is correct. Am I missing something important in the I2S input configuration? Since I'm relatively new to I2S, there might be some fundamental concept I'm overlooking.

Any help or suggestions would be greatly appreciated!

earlephilhower commented 4 hours ago

Please try the git master version, not the official release. There was an I2S input timing change to better match the spec which affects the left/right word clock (which would possibly cause data shifts). See the docs for full info, it's simple to get git running for most folks.

2592 is the specific PR.